diff options
Diffstat (limited to 'spec/lib/gitlab/gitaly_client')
-rw-r--r-- | spec/lib/gitlab/gitaly_client/operation_service_spec.rb | 47 | ||||
-rw-r--r-- | spec/lib/gitlab/gitaly_client/repository_service_spec.rb | 10 |
2 files changed, 43 insertions, 14 deletions
diff --git a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb index 27e7d446770..f0115aa6b2b 100644 --- a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb @@ -2,6 +2,9 @@ require 'spec_helper' +require 'google/rpc/status_pb' +require 'google/protobuf/well_known_types' + RSpec.describe Gitlab::GitalyClient::OperationService do let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, :repository) } @@ -185,11 +188,16 @@ RSpec.describe Gitlab::GitalyClient::OperationService do context 'with an exception with the UserMergeBranchError' do let(:permission_error) do - GRPC::PermissionDenied.new( + new_detailed_error( + GRPC::Core::StatusCodes::PERMISSION_DENIED, "GitLab: You are not allowed to push code to this project.", - { "grpc-status-details-bin" => - "\b\a\x129GitLab: You are not allowed to push code to this project.\x1A\xDE\x01\n/type.googleapis.com/gitaly.UserMergeBranchError\x12\xAA\x01\n\xA7\x01\n1You are not allowed to push code to this project.\x12\x03web\x1A\auser-15\"df15b32277d2c55c6c595845a87109b09c913c556 5d6e0f935ad9240655f64e883cd98fad6f9a17ee refs/heads/master\n" } - ) + Gitaly::UserMergeBranchError.new( + access_check: Gitaly::AccessCheckError.new( + error_message: "You are not allowed to push code to this project.", + protocol: "web", + user_id: "user-15", + changes: "df15b32277d2c55c6c595845a87109b09c913c556 5d6e0f935ad9240655f64e883cd98fad6f9a17ee refs/heads/master\n" + ))) end it 'raises PreRecieveError with the error message' do @@ -217,6 +225,27 @@ RSpec.describe Gitlab::GitalyClient::OperationService do expect { subject }.to raise_error(GRPC::PermissionDenied) end end + + context 'with ReferenceUpdateError' do + let(:reference_update_error) do + new_detailed_error(GRPC::Core::StatusCodes::FAILED_PRECONDITION, + "some ignored error message", + Gitaly::UserMergeBranchError.new( + reference_update: Gitaly::ReferenceUpdateError.new( + reference_name: "refs/heads/something", + old_oid: "1234", + new_oid: "6789" + ))) + end + + it 'returns nil' do + expect_any_instance_of(Gitaly::OperationService::Stub) + .to receive(:user_merge_branch).with(kind_of(Enumerator), kind_of(Hash)) + .and_raise(reference_update_error) + + expect(subject).to be_nil + end + end end describe '#user_ff_branch' do @@ -478,4 +507,14 @@ RSpec.describe Gitlab::GitalyClient::OperationService do end end end + + def new_detailed_error(error_code, error_message, details) + status_error = Google::Rpc::Status.new( + code: error_code, + message: error_message, + details: [Google::Protobuf::Any.pack(details)] + ) + + GRPC::BadStatus.new(error_code, error_message, { "grpc-status-details-bin" => Google::Rpc::Status.encode(status_error) }) + end end diff --git a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb index e5502a883b5..353726b56f6 100644 --- a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb @@ -21,16 +21,6 @@ RSpec.describe Gitlab::GitalyClient::RepositoryService do end end - describe '#cleanup' do - it 'sends a cleanup message' do - expect_any_instance_of(Gitaly::RepositoryService::Stub) - .to receive(:cleanup) - .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)) - - client.cleanup - end - end - describe '#garbage_collect' do it 'sends a garbage_collect message' do expect_any_instance_of(Gitaly::RepositoryService::Stub) |