Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-05-17 19:05:49 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-05-17 19:05:49 +0300
commit43a25d93ebdabea52f99b05e15b06250cd8f07d7 (patch)
treedceebdc68925362117480a5d672bcff122fb625b /spec/lib/gitlab/github_import/client_spec.rb
parent20c84b99005abd1c82101dfeff264ac50d2df211 (diff)
Add latest changes from gitlab-org/gitlab@16-0-stable-eev16.0.0-rc42
Diffstat (limited to 'spec/lib/gitlab/github_import/client_spec.rb')
-rw-r--r--spec/lib/gitlab/github_import/client_spec.rb78
1 files changed, 39 insertions, 39 deletions
diff --git a/spec/lib/gitlab/github_import/client_spec.rb b/spec/lib/gitlab/github_import/client_spec.rb
index e93d585bc3c..c9f7fd4f748 100644
--- a/spec/lib/gitlab/github_import/client_spec.rb
+++ b/spec/lib/gitlab/github_import/client_spec.rb
@@ -131,6 +131,16 @@ RSpec.describe Gitlab::GithubImport::Client, feature_category: :importers do
end
end
+ describe '#collaborators' do
+ it 'returns the collaborators' do
+ expect(client)
+ .to receive(:each_object)
+ .with(:collaborators, 'foo/bar')
+
+ client.collaborators('foo/bar')
+ end
+ end
+
describe '#branch_protection' do
it 'returns the protection details for the given branch' do
expect(client.octokit)
@@ -580,7 +590,10 @@ RSpec.describe Gitlab::GithubImport::Client, feature_category: :importers do
end
describe '#search_repos_by_name_graphql' do
- let(:expected_query) { 'test in:name is:public,private user:user repo:repo1 repo:repo2 org:org1 org:org2' }
+ let(:expected_query) do
+ 'test in:name is:public,private fork:true user:user repo:repo1 repo:repo2 org:org1 org:org2'
+ end
+
let(:expected_graphql_params) { "type: REPOSITORY, query: \"#{expected_query}\"" }
let(:expected_graphql) do
<<-TEXT
@@ -600,7 +613,8 @@ RSpec.describe Gitlab::GithubImport::Client, feature_category: :importers do
endCursor
hasNextPage
hasPreviousPage
- }
+ },
+ repositoryCount
}
}
TEXT
@@ -616,7 +630,7 @@ RSpec.describe Gitlab::GithubImport::Client, feature_category: :importers do
context 'when relation type option present' do
context 'when relation type is owned' do
- let(:expected_query) { 'test in:name is:public,private user:user' }
+ let(:expected_query) { 'test in:name is:public,private fork:true user:user' }
it 'searches for repositories within the organization based on name' do
expect(client.octokit).to receive(:post).with(
@@ -628,7 +642,7 @@ RSpec.describe Gitlab::GithubImport::Client, feature_category: :importers do
end
context 'when relation type is organization' do
- let(:expected_query) { 'test in:name is:public,private org:test-login' }
+ let(:expected_query) { 'test in:name is:public,private fork:true org:test-login' }
it 'searches for repositories within the organization based on name' do
expect(client.octokit).to receive(:post).with(
@@ -642,7 +656,7 @@ RSpec.describe Gitlab::GithubImport::Client, feature_category: :importers do
end
context 'when relation type is collaborated' do
- let(:expected_query) { 'test in:name is:public,private repo:repo1 repo:repo2' }
+ let(:expected_query) { 'test in:name is:public,private fork:true repo:repo1 repo:repo2' }
it 'searches for collaborated repositories based on name' do
expect(client.octokit).to receive(:post).with(
@@ -707,44 +721,30 @@ RSpec.describe Gitlab::GithubImport::Client, feature_category: :importers do
end
end
- describe '#search_repos_by_name' do
- let(:expected_query) { 'test in:name is:public,private user:user repo:repo1 repo:repo2 org:org1 org:org2' }
-
- it 'searches for repositories based on name' do
- expect(client.octokit).to receive(:search_repositories).with(expected_query, {})
+ describe '#count_repos_by_relation_type_graphql' do
+ relation_types = {
+ 'owned' => ' in:name is:public,private fork:true user:user',
+ 'collaborated' => ' in:name is:public,private fork:true repo:repo1 repo:repo2',
+ 'organization' => 'org:org1 org:org2'
+ }
- client.search_repos_by_name('test')
- end
+ relation_types.each do |relation_type, expected_query|
+ expected_graphql_params = "type: REPOSITORY, query: \"#{expected_query}\""
+ expected_graphql =
+ <<-TEXT
+ {
+ search(#{expected_graphql_params}) {
+ repositoryCount
+ }
+ }
+ TEXT
- context 'when pagination options present' do
- it 'searches for repositories via expected query' do
- expect(client.octokit).to receive(:search_repositories).with(
- expected_query, { page: 2, per_page: 25 }
+ it 'returns count by relation_type' do
+ expect(client.octokit).to receive(:post).with(
+ '/graphql', { query: expected_graphql }.to_json
)
- client.search_repos_by_name('test', { page: 2, per_page: 25 })
- end
- end
-
- context 'when Faraday error received from octokit', :aggregate_failures do
- let(:error_class) { described_class::CLIENT_CONNECTION_ERROR }
- let(:info_params) { { 'error.class': error_class } }
-
- it 'retries on error and succeeds' do
- allow_retry(:search_repositories)
-
- expect(Gitlab::Import::Logger).to receive(:info).with(hash_including(info_params)).once
-
- expect(client.search_repos_by_name('test')).to eq({})
- end
-
- it 'retries and does not succeed' do
- allow(client.octokit)
- .to receive(:search_repositories)
- .with(expected_query, {})
- .and_raise(error_class, 'execution expired')
-
- expect { client.search_repos_by_name('test') }.to raise_error(error_class, 'execution expired')
+ client.count_repos_by_relation_type_graphql(relation_type: relation_type)
end
end
end