diff options
Diffstat (limited to 'spec/lib/gitlab/gitaly_client/ref_service_spec.rb')
-rw-r--r-- | spec/lib/gitlab/gitaly_client/ref_service_spec.rb | 60 |
1 files changed, 50 insertions, 10 deletions
diff --git a/spec/lib/gitlab/gitaly_client/ref_service_spec.rb b/spec/lib/gitlab/gitaly_client/ref_service_spec.rb index 2e37c98a591..566bdbacf4a 100644 --- a/spec/lib/gitlab/gitaly_client/ref_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/ref_service_spec.rb @@ -241,30 +241,70 @@ RSpec.describe Gitlab::GitalyClient::RefService do end end - describe '#ref_exists?', :seed_helper do - it 'finds the master branch ref' do - expect(client.ref_exists?('refs/heads/master')).to eq(true) - end + describe '#ref_exists?' do + let(:ref) { 'refs/heads/master' } - it 'returns false for an illegal tag name ref' do - expect(client.ref_exists?('refs/tags/.this-tag-name-is-illegal')).to eq(false) - end + it 'sends a ref_exists message' do + expect_any_instance_of(Gitaly::RefService::Stub) + .to receive(:ref_exists) + .with(gitaly_request_with_params(ref: ref), kind_of(Hash)) + .and_return(double('ref_exists_response', value: true)) - it 'raises an argument error if the ref name parameter does not start with refs/' do - expect { client.ref_exists?('reXXXXX') }.to raise_error(ArgumentError) + expect(client.ref_exists?(ref)).to be true end end describe '#delete_refs' do let(:prefixes) { %w(refs/heads refs/keep-around) } + subject(:delete_refs) { client.delete_refs(except_with_prefixes: prefixes) } + it 'sends a delete_refs message' do expect_any_instance_of(Gitaly::RefService::Stub) .to receive(:delete_refs) .with(gitaly_request_with_params(except_with_prefix: prefixes), kind_of(Hash)) .and_return(double('delete_refs_response', git_error: "")) - client.delete_refs(except_with_prefixes: prefixes) + delete_refs + end + + context 'with a references locked error' do + let(:references_locked_error) do + new_detailed_error( + GRPC::Core::StatusCodes::FAILED_PRECONDITION, + "error message", + Gitaly::DeleteRefsError.new(references_locked: Gitaly::ReferencesLockedError.new)) + end + + it 'raises ReferencesLockedError' do + expect_any_instance_of(Gitaly::RefService::Stub).to receive(:delete_refs) + .with(gitaly_request_with_params(except_with_prefix: prefixes), kind_of(Hash)) + .and_raise(references_locked_error) + + expect { delete_refs }.to raise_error(Gitlab::Git::ReferencesLockedError) + end + end + + context 'with a invalid format error' do + let(:invalid_refs) {['\invali.\d/1', '\.invali/d/2']} + let(:invalid_reference_format_error) do + new_detailed_error( + GRPC::Core::StatusCodes::INVALID_ARGUMENT, + "error message", + Gitaly::DeleteRefsError.new(invalid_format: Gitaly::InvalidRefFormatError.new(refs: invalid_refs))) + end + + it 'raises InvalidRefFormatError' do + expect_any_instance_of(Gitaly::RefService::Stub) + .to receive(:delete_refs) + .with(gitaly_request_with_params(except_with_prefix: prefixes), kind_of(Hash)) + .and_raise(invalid_reference_format_error) + + expect { delete_refs }.to raise_error do |error| + expect(error).to be_a(Gitlab::Git::InvalidRefFormatError) + expect(error.message).to eq("references have an invalid format: #{invalid_refs.join(",")}") + end + end end end |