diff options
Diffstat (limited to 'spec/lib/gitlab/gitaly_client')
-rw-r--r-- | spec/lib/gitlab/gitaly_client/blob_service_spec.rb | 28 | ||||
-rw-r--r-- | spec/lib/gitlab/gitaly_client/ref_service_spec.rb | 32 | ||||
-rw-r--r-- | spec/lib/gitlab/gitaly_client/repository_service_spec.rb | 16 | ||||
-rw-r--r-- | spec/lib/gitlab/gitaly_client/wiki_service_spec.rb | 118 |
4 files changed, 49 insertions, 145 deletions
diff --git a/spec/lib/gitlab/gitaly_client/blob_service_spec.rb b/spec/lib/gitlab/gitaly_client/blob_service_spec.rb index f869c66337e..d02b4492216 100644 --- a/spec/lib/gitlab/gitaly_client/blob_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/blob_service_spec.rb @@ -174,20 +174,22 @@ RSpec.describe Gitlab::GitalyClient::BlobService do expect(service) .to receive(:list_blobs) .with(gitaly_request_with_params(expected_params), kind_of(Hash)) - .and_return([ - Gitaly::ListBlobsResponse.new(blobs: [ - Gitaly::ListBlobsResponse::Blob.new(oid: "012345", size: 8, data: "0x01"), - Gitaly::ListBlobsResponse::Blob.new(data: "23") - ]), - Gitaly::ListBlobsResponse.new(blobs: [ - Gitaly::ListBlobsResponse::Blob.new(data: "45"), - Gitaly::ListBlobsResponse::Blob.new(oid: "56", size: 4, data: "0x5"), - Gitaly::ListBlobsResponse::Blob.new(data: "6") - ]), - Gitaly::ListBlobsResponse.new(blobs: [ - Gitaly::ListBlobsResponse::Blob.new(oid: "78", size: 4, data: "0x78") + .and_return( + [ + Gitaly::ListBlobsResponse.new( + blobs: [ + Gitaly::ListBlobsResponse::Blob.new(oid: "012345", size: 8, data: "0x01"), + Gitaly::ListBlobsResponse::Blob.new(data: "23") + ]), + Gitaly::ListBlobsResponse.new( + blobs: [ + Gitaly::ListBlobsResponse::Blob.new(data: "45"), + Gitaly::ListBlobsResponse::Blob.new(oid: "56", size: 4, data: "0x5"), + Gitaly::ListBlobsResponse::Blob.new(data: "6") + ]), + Gitaly::ListBlobsResponse.new( + blobs: [Gitaly::ListBlobsResponse::Blob.new(oid: "78", size: 4, data: "0x78")]) ]) - ]) end blobs = subject.to_a diff --git a/spec/lib/gitlab/gitaly_client/ref_service_spec.rb b/spec/lib/gitlab/gitaly_client/ref_service_spec.rb index b7c21516c77..5ce88b06241 100644 --- a/spec/lib/gitlab/gitaly_client/ref_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/ref_service_spec.rb @@ -3,7 +3,8 @@ require 'spec_helper' RSpec.describe Gitlab::GitalyClient::RefService do - let(:project) { create(:project, :repository) } + let_it_be(:project) { create(:project, :repository) } + let(:storage_name) { project.repository_storage } let(:relative_path) { project.disk_path + '.git' } let(:repository) { project.repository } @@ -179,13 +180,22 @@ RSpec.describe Gitlab::GitalyClient::RefService do ) ) end + local_branches = target_commits.each_with_index.map do |gitaly_commit, i| Gitaly::Branch.new(name: "#{remote_name}/#{i}", target_commit: gitaly_commit) end - response = [ - Gitaly::FindLocalBranchesResponse.new(branches: branches[0, 2], local_branches: local_branches[0, 2]), - Gitaly::FindLocalBranchesResponse.new(branches: branches[2, 2], local_branches: local_branches[2, 2]) - ] + + response = if set_local_branches + [ + Gitaly::FindLocalBranchesResponse.new(local_branches: local_branches[0, 2]), + Gitaly::FindLocalBranchesResponse.new(local_branches: local_branches[2, 2]) + ] + else + [ + Gitaly::FindLocalBranchesResponse.new(branches: branches[0, 2]), + Gitaly::FindLocalBranchesResponse.new(branches: branches[2, 2]) + ] + end expect_any_instance_of(Gitaly::RefService::Stub) .to receive(:find_local_branches) @@ -220,18 +230,14 @@ RSpec.describe Gitlab::GitalyClient::RefService do end end - context 'when feature flag :gitaly_simplify_find_local_branches_response is enabled' do - before do - stub_feature_flags(gitaly_simplify_find_local_branches_response: true) - end + context 'when local_branches variable is not set' do + let(:set_local_branches) { false } it_behaves_like 'common examples' end - context 'when feature flag :gitaly_simplify_find_local_branches_response is disabled' do - before do - stub_feature_flags(gitaly_simplify_find_local_branches_response: false) - end + context 'when local_branches variable is set' do + let(:set_local_branches) { true } it_behaves_like 'common examples' end diff --git a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb index 63d32cb906f..58ace05b0d3 100644 --- a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb @@ -308,7 +308,7 @@ RSpec.describe Gitlab::GitalyClient::RepositoryService do end describe '#replicate' do - let(:source_repository) { Gitlab::Git::Repository.new('default', TEST_MUTABLE_REPO_PATH, '', 'group/project') } + let(:source_repository) { Gitlab::Git::Repository.new('default', 'repo/path', '', 'group/project') } it 'sends a replicate_repository message' do expect_any_instance_of(Gitaly::RepositoryService::Stub) @@ -343,4 +343,18 @@ RSpec.describe Gitlab::GitalyClient::RepositoryService do expect(client.full_path).to eq(path) end end + + describe "#find_license" do + it 'sends a find_license request with medium timeout' do + expect_any_instance_of(Gitaly::RepositoryService::Stub) + .to receive(:find_license) do |_service, _request, headers| + expect(headers[:deadline]).to be_between( + Gitlab::GitalyClient.fast_timeout.seconds.from_now.to_f, + Gitlab::GitalyClient.medium_timeout.seconds.from_now.to_f + ) + end + + client.find_license + end + end end diff --git a/spec/lib/gitlab/gitaly_client/wiki_service_spec.rb b/spec/lib/gitlab/gitaly_client/wiki_service_spec.rb deleted file mode 100644 index 8a169acb69c..00000000000 --- a/spec/lib/gitlab/gitaly_client/wiki_service_spec.rb +++ /dev/null @@ -1,118 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::GitalyClient::WikiService do - let(:project) { create(:project) } - let(:storage_name) { project.repository_storage } - let(:relative_path) { project.disk_path + '.git' } - let(:client) { described_class.new(project.repository) } - let(:commit) { create(:gitaly_commit) } - let(:page_version) { Gitaly::WikiPageVersion.new(format: 'markdown', commit: commit) } - let(:page_info) { { title: 'My Page', raw_data: 'a', version: page_version } } - - describe '#find_page' do - let(:response) do - [ - Gitaly::WikiFindPageResponse.new(page: Gitaly::WikiPage.new(page_info)), - Gitaly::WikiFindPageResponse.new(page: Gitaly::WikiPage.new(raw_data: 'b')) - ] - end - - let(:wiki_page) { subject.first } - let(:wiki_page_version) { subject.last } - - subject { client.find_page(title: 'My Page', version: 'master', dir: '') } - - it 'sends a wiki_find_page message' do - expect_any_instance_of(Gitaly::WikiService::Stub) - .to receive(:wiki_find_page) - .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)) - .and_return([].each) - - subject - end - - it 'concatenates the raw data and returns a pair of WikiPage and WikiPageVersion' do - expect_any_instance_of(Gitaly::WikiService::Stub) - .to receive(:wiki_find_page) - .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)) - .and_return(response.each) - - expect(wiki_page.title).to eq('My Page') - expect(wiki_page.raw_data).to eq('ab') - expect(wiki_page_version.format).to eq('markdown') - - expect(wiki_page.title).to be_utf8 - expect(wiki_page.path).to be_utf8 - expect(wiki_page.name).to be_utf8 - end - end - - describe '#load_all_pages' do - let(:page_2_info) { { title: 'My Page 2', raw_data: 'c', version: page_version } } - let(:response) do - [ - Gitaly::WikiGetAllPagesResponse.new(page: Gitaly::WikiPage.new(page_info)), - Gitaly::WikiGetAllPagesResponse.new(page: Gitaly::WikiPage.new(raw_data: 'b')), - Gitaly::WikiGetAllPagesResponse.new(end_of_page: true), - Gitaly::WikiGetAllPagesResponse.new(page: Gitaly::WikiPage.new(page_2_info)), - Gitaly::WikiGetAllPagesResponse.new(page: Gitaly::WikiPage.new(raw_data: 'd')), - Gitaly::WikiGetAllPagesResponse.new(end_of_page: true) - ] - end - - let(:wiki_page_1) { subject[0].first } - let(:wiki_page_1_version) { subject[0].last } - let(:wiki_page_2) { subject[1].first } - let(:wiki_page_2_version) { subject[1].last } - - subject { client.load_all_pages } - - it 'sends a wiki_get_all_pages message' do - expect_any_instance_of(Gitaly::WikiService::Stub) - .to receive(:wiki_get_all_pages) - .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)) - .and_return([].each) - - subject - end - - it 'sends a limit of 0 to wiki_get_all_pages' do - expect_any_instance_of(Gitaly::WikiService::Stub) - .to receive(:wiki_get_all_pages) - .with(gitaly_request_with_params(limit: 0), kind_of(Hash)) - .and_return([].each) - - subject - end - - it 'concatenates the raw data and returns a pair of WikiPage and WikiPageVersion for each page' do - expect_any_instance_of(Gitaly::WikiService::Stub) - .to receive(:wiki_get_all_pages) - .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)) - .and_return(response.each) - - expect(subject.size).to be(2) - expect(wiki_page_1.title).to eq('My Page') - expect(wiki_page_1.raw_data).to eq('ab') - expect(wiki_page_1_version.format).to eq('markdown') - expect(wiki_page_2.title).to eq('My Page 2') - expect(wiki_page_2.raw_data).to eq('cd') - expect(wiki_page_2_version.format).to eq('markdown') - end - - context 'with limits' do - subject { client.load_all_pages(limit: 1) } - - it 'sends a request with the limit' do - expect_any_instance_of(Gitaly::WikiService::Stub) - .to receive(:wiki_get_all_pages) - .with(gitaly_request_with_params(limit: 1), kind_of(Hash)) - .and_return([].each) - - subject - end - end - end -end |