diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-11-19 11:27:35 +0300 |
commit | 7e9c479f7de77702622631cff2628a9c8dcbc627 (patch) | |
tree | c8f718a08e110ad7e1894510980d2155a6549197 /spec/lib/gitlab/github_import | |
parent | e852b0ae16db4052c1c567d9efa4facc81146e88 (diff) |
Add latest changes from gitlab-org/gitlab@13-6-stable-eev13.6.0-rc42
Diffstat (limited to 'spec/lib/gitlab/github_import')
4 files changed, 126 insertions, 9 deletions
diff --git a/spec/lib/gitlab/github_import/client_spec.rb b/spec/lib/gitlab/github_import/client_spec.rb index 5f6ab42d0d2..bc734644d29 100644 --- a/spec/lib/gitlab/github_import/client_spec.rb +++ b/spec/lib/gitlab/github_import/client_spec.rb @@ -203,16 +203,40 @@ RSpec.describe Gitlab::GithubImport::Client do describe '#requests_remaining?' do let(:client) { described_class.new('foo') } - it 'returns true if enough requests remain' do - expect(client).to receive(:remaining_requests).and_return(9000) + context 'when default requests limit is set' do + before do + allow(client).to receive(:requests_limit).and_return(5000) + end + + it 'returns true if enough requests remain' do + expect(client).to receive(:remaining_requests).and_return(9000) + + expect(client.requests_remaining?).to eq(true) + end + + it 'returns false if not enough requests remain' do + expect(client).to receive(:remaining_requests).and_return(1) - expect(client.requests_remaining?).to eq(true) + expect(client.requests_remaining?).to eq(false) + end end - it 'returns false if not enough requests remain' do - expect(client).to receive(:remaining_requests).and_return(1) + context 'when search requests limit is set' do + before do + allow(client).to receive(:requests_limit).and_return(described_class::SEARCH_MAX_REQUESTS_PER_MINUTE) + end + + it 'returns true if enough requests remain' do + expect(client).to receive(:remaining_requests).and_return(described_class::SEARCH_RATE_LIMIT_THRESHOLD + 1) + + expect(client.requests_remaining?).to eq(true) + end + + it 'returns false if not enough requests remain' do + expect(client).to receive(:remaining_requests).and_return(described_class::SEARCH_RATE_LIMIT_THRESHOLD - 1) - expect(client.requests_remaining?).to eq(false) + expect(client.requests_remaining?).to eq(false) + end end end @@ -262,6 +286,16 @@ RSpec.describe Gitlab::GithubImport::Client do end end + describe '#requests_limit' do + it 'returns requests limit' do + client = described_class.new('foo') + rate_limit = double(limit: 1) + + expect(client.octokit).to receive(:rate_limit).and_return(rate_limit) + expect(client.requests_limit).to eq(1) + end + end + describe '#rate_limit_resets_in' do it 'returns the number of seconds after which the rate limit is reset' do client = described_class.new('foo') @@ -299,6 +333,32 @@ RSpec.describe Gitlab::GithubImport::Client do end end + describe '#web_endpoint' do + let(:client) { described_class.new('foo') } + + context 'without a custom endpoint configured in Omniauth' do + it 'returns the default web endpoint' do + expect(client) + .to receive(:custom_api_endpoint) + .and_return(nil) + + expect(client.web_endpoint).to eq('https://github.com') + end + end + + context 'with a custom endpoint configured in Omniauth' do + it 'returns the custom endpoint' do + endpoint = 'https://github.kittens.com' + + expect(client) + .to receive(:custom_api_endpoint) + .and_return(endpoint) + + expect(client.web_endpoint).to eq(endpoint) + end + end + end + describe '#custom_api_endpoint' do let(:client) { described_class.new('foo') } @@ -391,4 +451,61 @@ RSpec.describe Gitlab::GithubImport::Client do expect(client.rate_limiting_enabled?).to eq(false) end end + + describe 'search' do + let(:client) { described_class.new('foo') } + let(:user) { double(:user, login: 'user') } + let(:org1) { double(:org, login: 'org1') } + let(:org2) { double(:org, login: 'org2') } + let(:repo1) { double(:repo, full_name: 'repo1') } + let(:repo2) { double(:repo, full_name: 'repo2') } + + before do + allow(client) + .to receive(:each_object) + .with(:repos, nil, { affiliation: 'collaborator' }) + .and_return([repo1, repo2].to_enum) + + allow(client) + .to receive(:each_object) + .with(:organizations) + .and_return([org1, org2].to_enum) + + allow(client.octokit).to receive(:user).and_return(user) + end + + describe '#search_repos_by_name' do + it 'searches for repositories based on name' do + expected_search_query = 'test in:name is:public,private user:user repo:repo1 repo:repo2 org:org1 org:org2' + + expect(client).to receive(:each_page).with(:search_repositories, expected_search_query) + + client.search_repos_by_name('test') + end + end + + describe '#search_query' do + it 'returns base search query' do + result = client.search_query(str: 'test', type: :test, include_collaborations: false, include_orgs: false) + + expect(result).to eq('test in:test is:public,private user:user') + end + + context 'when include_collaborations is true' do + it 'returns search query including users' do + result = client.search_query(str: 'test', type: :test, include_collaborations: true, include_orgs: false) + + expect(result).to eq('test in:test is:public,private user:user repo:repo1 repo:repo2') + end + end + + context 'when include_orgs is true' do + it 'returns search query including users' do + result = client.search_query(str: 'test', type: :test, include_collaborations: false, include_orgs: true) + + expect(result).to eq('test in:test is:public,private user:user org:org1 org:org2') + end + end + end + end end diff --git a/spec/lib/gitlab/github_import/importer/lfs_object_importer_spec.rb b/spec/lib/gitlab/github_import/importer/lfs_object_importer_spec.rb index add554992f1..188c56ae81f 100644 --- a/spec/lib/gitlab/github_import/importer/lfs_object_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/lfs_object_importer_spec.rb @@ -12,7 +12,7 @@ RSpec.describe Gitlab::GithubImport::Importer::LfsObjectImporter do } end - let(:lfs_download_object) { LfsDownloadObject.new(lfs_attributes) } + let(:lfs_download_object) { LfsDownloadObject.new(**lfs_attributes) } let(:github_lfs_object) { Gitlab::GithubImport::Representation::LfsObject.new(lfs_attributes) } let(:importer) { described_class.new(github_lfs_object, project, nil) } diff --git a/spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb b/spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb index 1f7b14661c2..6188ba8ec3f 100644 --- a/spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/lfs_objects_importer_spec.rb @@ -15,7 +15,7 @@ RSpec.describe Gitlab::GithubImport::Importer::LfsObjectsImporter do } end - let(:lfs_download_object) { LfsDownloadObject.new(lfs_attributes) } + let(:lfs_download_object) { LfsDownloadObject.new(**lfs_attributes) } describe '#parallel?' do it 'returns true when running in parallel mode' do diff --git a/spec/lib/gitlab/github_import/sequential_importer_spec.rb b/spec/lib/gitlab/github_import/sequential_importer_spec.rb index fe13fcd2568..a5e89049ed9 100644 --- a/spec/lib/gitlab/github_import/sequential_importer_spec.rb +++ b/spec/lib/gitlab/github_import/sequential_importer_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Gitlab::GithubImport::SequentialImporter do describe '#execute' do it 'imports a project in sequence' do repository = double(:repository) - project = double(:project, id: 1, repository: repository) + project = double(:project, id: 1, repository: repository, import_url: 'http://t0ken@github.another-domain.com/repo-org/repo.git') importer = described_class.new(project, token: 'foo') expect_next_instance_of(Gitlab::GithubImport::Importer::RepositoryImporter) do |instance| |