diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 21:18:33 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-16 21:18:33 +0300 |
commit | f64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch) | |
tree | a2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /spec/services/import/github_service_spec.rb | |
parent | bfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff) |
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'spec/services/import/github_service_spec.rb')
-rw-r--r-- | spec/services/import/github_service_spec.rb | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/services/import/github_service_spec.rb b/spec/services/import/github_service_spec.rb index 408d7767254..776df01d399 100644 --- a/spec/services/import/github_service_spec.rb +++ b/spec/services/import/github_service_spec.rb @@ -54,6 +54,62 @@ RSpec.describe Import::GithubService do expect { subject.execute(access_params, :github) }.to raise_error(exception) end + + context 'repository size validation' do + let(:repository_double) { double(name: 'repository', size: 99) } + + before do + expect(client).to receive(:repository).and_return(repository_double) + + allow_next_instance_of(Gitlab::LegacyGithubImport::ProjectCreator) do |creator| + allow(creator).to receive(:execute).and_return(double(persisted?: true)) + end + end + + context 'when there is no repository size limit defined' do + it 'skips the check and succeeds' do + expect(subject.execute(access_params, :github)).to include(status: :success) + end + end + + context 'when the target namespace repository size limit is defined' do + let_it_be(:group) { create(:group, repository_size_limit: 100) } + + before do + params[:target_namespace] = group.full_path + end + + it 'succeeds when the repository is smaller than the limit' do + expect(subject.execute(access_params, :github)).to include(status: :success) + end + + it 'returns error when the repository is larger than the limit' do + allow(repository_double).to receive(:size).and_return(101) + + expect(subject.execute(access_params, :github)).to include(size_limit_error) + end + end + + context 'when target namespace repository limit is not defined' do + let_it_be(:group) { create(:group) } + + before do + stub_application_setting(repository_size_limit: 100) + end + + context 'when application size limit is defined' do + it 'succeeds when the repository is smaller than the limit' do + expect(subject.execute(access_params, :github)).to include(status: :success) + end + + it 'returns error when the repository is larger than the limit' do + allow(repository_double).to receive(:size).and_return(101) + + expect(subject.execute(access_params, :github)).to include(size_limit_error) + end + end + end + end end context 'when remove_legacy_github_client feature flag is enabled' do @@ -71,4 +127,12 @@ RSpec.describe Import::GithubService do include_examples 'handles errors', Gitlab::LegacyGithubImport::Client end + + def size_limit_error + { + status: :error, + http_status: :unprocessable_entity, + message: '"repository" size (101 Bytes) is larger than the limit of 100 Bytes.' + } + end end |