diff options
Diffstat (limited to 'spec/lib/gitlab/gitaly_client')
4 files changed, 137 insertions, 65 deletions
diff --git a/spec/lib/gitlab/gitaly_client/commit_service_spec.rb b/spec/lib/gitlab/gitaly_client/commit_service_spec.rb index ff3cade07c0..252d20d9c3a 100644 --- a/spec/lib/gitlab/gitaly_client/commit_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/commit_service_spec.rb @@ -63,6 +63,47 @@ RSpec.describe Gitlab::GitalyClient::CommitService do end end + context 'when given a whitespace param' do + context 'and the param is true' do + it 'uses the ignore all white spaces const' do + request = Gitaly::CommitDiffRequest.new + + expect(Gitaly::CommitDiffRequest).to receive(:new) + .with(hash_including(whitespace_changes: Gitaly::CommitDiffRequest::WhitespaceChanges::WHITESPACE_CHANGES_IGNORE_ALL)).and_return(request) + + expect_any_instance_of(Gitaly::DiffService::Stub).to receive(:commit_diff).with(request, kind_of(Hash)) + + client.diff_from_parent(commit, ignore_whitespace_change: true) + end + end + + context 'and the param is false' do + it 'does not set a whitespace param' do + request = Gitaly::CommitDiffRequest.new + + expect(Gitaly::CommitDiffRequest).to receive(:new) + .with(hash_not_including(:whitespace_changes)).and_return(request) + + expect_any_instance_of(Gitaly::DiffService::Stub).to receive(:commit_diff).with(request, kind_of(Hash)) + + client.diff_from_parent(commit, ignore_whitespace_change: false) + end + end + end + + context 'when given no whitespace param' do + it 'does not set a whitespace param' do + request = Gitaly::CommitDiffRequest.new + + expect(Gitaly::CommitDiffRequest).to receive(:new) + .with(hash_not_including(:whitespace_changes)).and_return(request) + + expect_any_instance_of(Gitaly::DiffService::Stub).to receive(:commit_diff).with(request, kind_of(Hash)) + + client.diff_from_parent(commit) + end + end + it 'returns a Gitlab::GitalyClient::DiffStitcher' do ret = client.diff_from_parent(commit) diff --git a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb index 82d5d0f292b..84672eb81c0 100644 --- a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GitalyClient::OperationService do +RSpec.describe Gitlab::GitalyClient::OperationService, feature_category: :source_code_management do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, :repository) } @@ -42,21 +42,6 @@ RSpec.describe Gitlab::GitalyClient::OperationService do expect(subject.dereferenced_target).to eq(commit) end - context "when pre_receive_error is present" do - let(:response) do - Gitaly::UserCreateBranchResponse.new(pre_receive_error: "GitLab: something failed") - end - - it "throws a PreReceive exception" do - expect_any_instance_of(Gitaly::OperationService::Stub) - .to receive(:user_create_branch).with(request, kind_of(Hash)) - .and_return(response) - - expect { subject }.to raise_error( - Gitlab::Git::PreReceiveError, "something failed") - end - end - context 'with structured errors' do context 'with CustomHookError' do let(:stdout) { nil } @@ -232,21 +217,6 @@ RSpec.describe Gitlab::GitalyClient::OperationService do subject end - context "when pre_receive_error is present" do - let(:response) do - Gitaly::UserDeleteBranchResponse.new(pre_receive_error: "GitLab: something failed") - end - - it "throws a PreReceive exception" do - expect_any_instance_of(Gitaly::OperationService::Stub) - .to receive(:user_delete_branch).with(request, kind_of(Hash)) - .and_return(response) - - expect { subject }.to raise_error( - Gitlab::Git::PreReceiveError, "something failed") - end - end - context 'with a custom hook error' do let(:stdout) { nil } let(:stderr) { nil } @@ -309,12 +279,39 @@ RSpec.describe Gitlab::GitalyClient::OperationService do describe '#user_merge_branch' do let(:target_branch) { 'master' } + let(:target_sha) { repository.commit(target_branch).sha } let(:source_sha) { '5937ac0a7beb003549fc5fd26fc247adbce4a52e' } let(:message) { 'Merge a branch' } - subject { client.user_merge_branch(user, source_sha, target_branch, message) {} } + subject do + client.user_merge_branch(user, + source_sha: source_sha, + target_branch: target_branch, + target_sha: target_sha, + message: message + ) {} + end + + it 'sends a user_merge_branch message', :freeze_time do + first_request = + Gitaly::UserMergeBranchRequest.new( + repository: repository.gitaly_repository, + user: gitaly_user, + commit_id: source_sha, + branch: target_branch, + expected_old_oid: target_sha, + message: message, + timestamp: Google::Protobuf::Timestamp.new(seconds: Time.now.utc.to_i) + ) + + second_request = Gitaly::UserMergeBranchRequest.new(apply: true) + + expect_next_instance_of(Gitlab::GitalyClient::QueueEnumerator) do |instance| + expect(instance).to receive(:push).with(first_request).and_call_original + expect(instance).to receive(:push).with(second_request).and_call_original + expect(instance).to receive(:close) + end - it 'sends a user_merge_branch message' do expect(subject).to be_a(Gitlab::Git::OperationService::BranchUpdate) expect(subject.newrev).to be_present expect(subject.repo_created).to be(false) @@ -461,12 +458,14 @@ RSpec.describe Gitlab::GitalyClient::OperationService do describe '#user_ff_branch' do let(:target_branch) { 'my-branch' } + let(:target_sha) { '6d394385cf567f80a8fd85055db1ab4c5295806f' } let(:source_sha) { 'cfe32cf61b73a0d5e9f13e774abde7ff789b1660' } let(:request) do Gitaly::UserFFBranchRequest.new( repository: repository.gitaly_repository, branch: target_branch, commit_id: source_sha, + expected_old_oid: target_sha, user: gitaly_user ) end @@ -487,7 +486,13 @@ RSpec.describe Gitlab::GitalyClient::OperationService do .and_return(response) end - subject { client.user_ff_branch(user, source_sha, target_branch) } + subject do + client.user_ff_branch(user, + source_sha: source_sha, + target_branch: target_branch, + target_sha: target_sha + ) + end it 'sends a user_ff_branch message and returns a BranchUpdate object' do expect(subject).to be_a(Gitlab::Git::OperationService::BranchUpdate) @@ -574,16 +579,6 @@ RSpec.describe Gitlab::GitalyClient::OperationService do ) end - context 'when errors are not raised but returned in the response' do - before do - expect_any_instance_of(Gitaly::OperationService::Stub) - .to receive(:user_cherry_pick).with(kind_of(Gitaly::UserCherryPickRequest), kind_of(Hash)) - .and_return(response) - end - - it_behaves_like 'cherry pick and revert errors' - end - context 'when AccessCheckError is raised' do let(:raised_error) do new_detailed_error( @@ -1149,18 +1144,6 @@ RSpec.describe Gitlab::GitalyClient::OperationService do end end - context 'with pre-receive error' do - before do - expect_any_instance_of(Gitaly::OperationService::Stub) - .to receive(:user_create_tag) - .and_return(Gitaly::UserCreateTagResponse.new(pre_receive_error: "GitLab: something failed")) - end - - it 'raises a PreReceiveError' do - expect { add_tag }.to raise_error(Gitlab::Git::PreReceiveError, "something failed") - end - end - context 'with internal error' do before do expect_any_instance_of(Gitaly::OperationService::Stub) diff --git a/spec/lib/gitlab/gitaly_client/ref_service_spec.rb b/spec/lib/gitlab/gitaly_client/ref_service_spec.rb index 14d5cef103b..09d8ea3cc0a 100644 --- a/spec/lib/gitlab/gitaly_client/ref_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/ref_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GitalyClient::RefService do +RSpec.describe Gitlab::GitalyClient::RefService, feature_category: :gitaly do let_it_be(:project) { create(:project, :repository, create_tag: 'test') } let(:storage_name) { project.repository_storage } @@ -390,10 +390,15 @@ RSpec.describe Gitlab::GitalyClient::RefService do end describe '#list_refs' do + let(:oid) { project.repository.commit.id } + it 'sends a list_refs message' do expect_any_instance_of(Gitaly::RefService::Stub) .to receive(:list_refs) - .with(gitaly_request_with_params(patterns: ['refs/heads/']), kind_of(Hash)) + .with( + gitaly_request_with_params(patterns: ['refs/heads/'], pointing_at_oids: [], peel_tags: false), + kind_of(Hash) + ) .and_call_original client.list_refs @@ -407,6 +412,24 @@ RSpec.describe Gitlab::GitalyClient::RefService do client.list_refs([Gitlab::Git::TAG_REF_PREFIX]) end + + it 'accepts a pointing_at_oids argument' do + expect_any_instance_of(Gitaly::RefService::Stub) + .to receive(:list_refs) + .with(gitaly_request_with_params(pointing_at_oids: [oid]), kind_of(Hash)) + .and_call_original + + client.list_refs(pointing_at_oids: [oid]) + end + + it 'accepts a peel_tags argument' do + expect_any_instance_of(Gitaly::RefService::Stub) + .to receive(:list_refs) + .with(gitaly_request_with_params(peel_tags: true), kind_of(Hash)) + .and_call_original + + client.list_refs(peel_tags: true) + end end describe '#find_refs_by_oid' do diff --git a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb index 5eb60d2caa5..434550186c1 100644 --- a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb @@ -5,7 +5,7 @@ require 'spec_helper' RSpec.describe Gitlab::GitalyClient::RepositoryService do using RSpec::Parameterized::TableSyntax - let(:project) { create(:project) } + let_it_be(:project) { create(:project, :repository) } let(:storage_name) { project.repository_storage } let(:relative_path) { project.disk_path + '.git' } let(:client) { described_class.new(project.repository) } @@ -22,13 +22,38 @@ RSpec.describe Gitlab::GitalyClient::RepositoryService do end describe '#optimize_repository' do - it 'sends a optimize_repository message' do - expect_any_instance_of(Gitaly::RepositoryService::Stub) - .to receive(:optimize_repository) - .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)) - .and_return(double(:optimize_repository)) + shared_examples 'a repository optimization' do + it 'sends a optimize_repository message' do + expect_any_instance_of(Gitaly::RepositoryService::Stub) + .to receive(:optimize_repository) + .with(gitaly_request_with_params( + strategy: expected_strategy + ), kind_of(Hash)) + .and_call_original + + client.optimize_repository(**params) + end + end + + context 'with default parameter' do + let(:params) { {} } + let(:expected_strategy) { :STRATEGY_HEURISTICAL } + + it_behaves_like 'a repository optimization' + end + + context 'with heuristical housekeeping strategy' do + let(:params) { { eager: false } } + let(:expected_strategy) { :STRATEGY_HEURISTICAL } + + it_behaves_like 'a repository optimization' + end + + context 'with eager housekeeping strategy' do + let(:params) { { eager: true } } + let(:expected_strategy) { :STRATEGY_EAGER } - client.optimize_repository + it_behaves_like 'a repository optimization' end end |