diff options
Diffstat (limited to 'spec/lib/gitlab/gitaly_client')
4 files changed, 214 insertions, 37 deletions
diff --git a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb index 9055b284119..bd0341d51bf 100644 --- a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb @@ -567,20 +567,58 @@ RSpec.describe Gitlab::GitalyClient::OperationService, feature_category: :source end end - describe '#user_cherry_pick' do + describe '#user_cherry_pick', :freeze_time do let(:response_class) { Gitaly::UserCherryPickResponse } + let(:sha) { '54cec5282aa9f21856362fe321c800c236a61615' } + let(:branch_name) { 'master' } + let(:cherry_pick_message) { 'Cherry-pick message' } + let(:time) { Time.now.utc } + + let(:branch_update) do + Gitaly::OperationBranchUpdate.new( + commit_id: sha, + repo_created: false, + branch_created: false + ) + end + + let(:request) do + Gitaly::UserCherryPickRequest.new( + repository: repository.gitaly_repository, + user: gitaly_user, + commit: repository.commit.to_gitaly_commit, + branch_name: branch_name, + start_branch_name: branch_name, + start_repository: repository.gitaly_repository, + message: cherry_pick_message, + timestamp: Google::Protobuf::Timestamp.new(seconds: time.to_i) + ) + end + + let(:response) { Gitaly::UserCherryPickResponse.new(branch_update: branch_update) } subject do client.user_cherry_pick( user: user, commit: repository.commit, - branch_name: 'master', - message: 'Cherry-pick message', - start_branch_name: 'master', + branch_name: branch_name, + message: cherry_pick_message, + start_branch_name: branch_name, start_repository: repository ) end + it 'sends a user_cherry_pick message and returns a BranchUpdate' do + expect_any_instance_of(Gitaly::OperationService::Stub) + .to receive(:user_cherry_pick).with(request, kind_of(Hash)) + .and_return(response) + + expect(subject).to be_a(Gitlab::Git::OperationService::BranchUpdate) + expect(subject.newrev).to be_present + expect(subject.repo_created).to be(false) + expect(subject.branch_created).to be(false) + end + context 'when AccessCheckError is raised' do let(:raised_error) do new_detailed_error( @@ -641,27 +679,68 @@ RSpec.describe Gitlab::GitalyClient::OperationService, feature_category: :source end end - describe '#user_revert' do - let(:response_class) { Gitaly::UserRevertResponse } + describe '#user_revert', :freeze_time do + let(:sha) { '54cec5282aa9f21856362fe321c800c236a61615' } + let(:branch_name) { 'master' } + let(:revert_message) { 'revert message' } + let(:time) { Time.now.utc } + + let(:branch_update) do + Gitaly::OperationBranchUpdate.new( + commit_id: sha, + repo_created: false, + branch_created: false + ) + end + + let(:request) do + Gitaly::UserRevertRequest.new( + repository: repository.gitaly_repository, + user: gitaly_user, + commit: repository.commit.to_gitaly_commit, + branch_name: branch_name, + start_branch_name: branch_name, + start_repository: repository.gitaly_repository, + message: revert_message, + timestamp: Google::Protobuf::Timestamp.new(seconds: time.to_i) + ) + end + + let(:response) { Gitaly::UserRevertResponse.new(branch_update: branch_update) } subject do client.user_revert( user: user, commit: repository.commit, - branch_name: 'master', - message: 'Revert message', - start_branch_name: 'master', + branch_name: branch_name, + message: revert_message, + start_branch_name: branch_name, start_repository: repository ) end - before do + it 'sends a user_revert message and returns a BranchUpdate' do expect_any_instance_of(Gitaly::OperationService::Stub) - .to receive(:user_revert).with(kind_of(Gitaly::UserRevertRequest), kind_of(Hash)) - .and_return(response) + .to receive(:user_revert).with(request, kind_of(Hash)) + .and_return(response) + + expect(subject).to be_a(Gitlab::Git::OperationService::BranchUpdate) + expect(subject.newrev).to be_present + expect(subject.repo_created).to be(false) + expect(subject.branch_created).to be(false) end - it_behaves_like 'cherry pick and revert errors' + context 'when errors are raised' do + let(:response_class) { Gitaly::UserRevertResponse } + + before do + expect_any_instance_of(Gitaly::OperationService::Stub) + .to receive(:user_revert).with(kind_of(Gitaly::UserRevertRequest), kind_of(Hash)) + .and_return(response) + end + + it_behaves_like 'cherry pick and revert errors' + end end describe '#rebase' do diff --git a/spec/lib/gitlab/gitaly_client/ref_service_spec.rb b/spec/lib/gitlab/gitaly_client/ref_service_spec.rb index fe04ad36e9a..ae9276cf90b 100644 --- a/spec/lib/gitlab/gitaly_client/ref_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/ref_service_spec.rb @@ -314,6 +314,116 @@ RSpec.describe Gitlab::GitalyClient::RefService, feature_category: :gitaly do end end + describe '#update_refs' do + let(:old_sha) { '0b4bc9a49b562e85de7cc9e834518ea6828729b9' } + let(:new_sha) { Gitlab::Git::EMPTY_TREE_ID } + let(:reference) { 'refs/does/not/exist' } + let(:expected_param) do + Gitaly::UpdateReferencesRequest::Update.new( + old_object_id: old_sha, + new_object_id: new_sha, + reference: reference + ) + end + + let(:ref_list) do + [ + { + old_sha: old_sha, + new_sha: new_sha, + reference: reference + } + ] + end + + subject(:update_refs) { client.update_refs(ref_list: ref_list) } + + it 'sends a update_refs message' do + expect_any_instance_of(Gitaly::RefService::Stub) + .to receive(:update_references) + .with(array_including(gitaly_request_with_params(updates: [expected_param])), kind_of(Hash)) + .and_return(double('update_refs_response', git_error: "")) + + update_refs + end + + context 'with a generic BadStatus error' do + let(:generic_error) do + GRPC::BadStatus.new( + GRPC::Core::StatusCodes::FAILED_PRECONDITION, + "error message" + ) + end + + it 'raises the BadStatus error' do + expect_any_instance_of(Gitaly::RefService::Stub) + .to receive(:update_references) + .with(array_including(gitaly_request_with_params(updates: [expected_param])), kind_of(Hash)) + .and_raise(generic_error) + + expect { update_refs }.to raise_error(GRPC::BadStatus) + end + end + + context 'with a reference state mismatch error' do + let(:reference_state_mismatch_error) do + new_detailed_error( + GRPC::Core::StatusCodes::FAILED_PRECONDITION, + "error message", + Gitaly::UpdateReferencesError.new(reference_state_mismatch: Gitaly::ReferenceStateMismatchError.new)) + end + + it 'raises ReferencesLockedError' do + expect_any_instance_of(Gitaly::RefService::Stub) + .to receive(:update_references) + .with(array_including(gitaly_request_with_params(updates: [expected_param])), kind_of(Hash)) + .and_raise(reference_state_mismatch_error) + + expect { update_refs }.to raise_error(Gitlab::Git::ReferenceStateMismatchError) + end + end + + context 'with a references locked error' do + let(:references_locked_error) do + new_detailed_error( + GRPC::Core::StatusCodes::FAILED_PRECONDITION, + "error message", + Gitaly::UpdateReferencesError.new(references_locked: Gitaly::ReferencesLockedError.new)) + end + + it 'raises ReferencesLockedError' do + expect_any_instance_of(Gitaly::RefService::Stub) + .to receive(:update_references) + .with(array_including(gitaly_request_with_params(updates: [expected_param])), kind_of(Hash)) + .and_raise(references_locked_error) + + expect { update_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::UpdateReferencesError.new(invalid_format: Gitaly::InvalidRefFormatError.new(refs: invalid_refs))) + end + + it 'raises InvalidRefFormatError' do + expect_any_instance_of(Gitaly::RefService::Stub) + .to receive(:update_references) + .with(array_including(gitaly_request_with_params(updates: [expected_param])), kind_of(Hash)) + .and_raise(invalid_reference_format_error) + + expect { update_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 + describe '#delete_refs' do let(:prefixes) { %w(refs/heads refs/keep-around) } diff --git a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb index d8ae7d70bb2..8e0e4525729 100644 --- a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb @@ -319,19 +319,8 @@ RSpec.describe Gitlab::GitalyClient::RepositoryService, feature_category: :gital end end - describe '#create_from_snapshot' do - it 'sends a create_repository_from_snapshot message' do - expect_any_instance_of(Gitaly::RepositoryService::Stub) - .to receive(:create_repository_from_snapshot) - .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)) - .and_return(double) - - client.create_from_snapshot('http://example.com?wiki=1', 'Custom xyz') - end - end - describe '#raw_changes_between' do - it 'sends a create_repository_from_snapshot message' do + it 'sends a get_raw_changes message' do expect_any_instance_of(Gitaly::RepositoryService::Stub) .to receive(:get_raw_changes) .with(gitaly_request_with_path(storage_name, relative_path), kind_of(Hash)) diff --git a/spec/lib/gitlab/gitaly_client/with_feature_flag_actors_spec.rb b/spec/lib/gitlab/gitaly_client/with_feature_flag_actors_spec.rb index 42153a9a3d8..49b4f90cdf9 100644 --- a/spec/lib/gitlab/gitaly_client/with_feature_flag_actors_spec.rb +++ b/spec/lib/gitlab/gitaly_client/with_feature_flag_actors_spec.rb @@ -10,6 +10,8 @@ RSpec.describe Gitlab::GitalyClient::WithFeatureFlagActors do end.new end + let_it_be(:group) { create(:group) } + describe '#user_actor' do context 'when user is not available in ApplicationContext' do it 'returns nil' do @@ -40,7 +42,7 @@ RSpec.describe Gitlab::GitalyClient::WithFeatureFlagActors do describe '#repository, #project_actor, #group_actor' do context 'when normal project repository' do - let_it_be(:project) { create(:project, group: create(:group)) } + let_it_be(:project) { create(:project, group: group) } let(:expected_project) { project } let(:expected_group) { Feature::Gitaly::ActorWrapper.new(::Group, project.group.id) } @@ -58,7 +60,7 @@ RSpec.describe Gitlab::GitalyClient::WithFeatureFlagActors do end context 'when project wiki repository' do - let_it_be(:project) { create(:project, :wiki_repo, group: create(:group)) } + let_it_be(:project) { create(:project, :wiki_repo, group: group) } let(:expected_project) { nil } let(:expected_group) { nil } @@ -112,7 +114,7 @@ RSpec.describe Gitlab::GitalyClient::WithFeatureFlagActors do end context 'when project snippet' do - let_it_be(:project) { create(:project, group: create(:group)) } + let_it_be(:project) { create(:project, group: group) } let(:snippet) { create(:project_snippet, project: project) } let(:expected_project) { nil } let(:expected_group) { nil } @@ -131,23 +133,20 @@ RSpec.describe Gitlab::GitalyClient::WithFeatureFlagActors do end context 'when project design' do - let_it_be(:design_repo) do - create(:design_management_repository, project: create(:project, group: create(:group))) - end - - let(:expected_project) { design_repo.project } - let(:expected_group) { design_repo.project.group } + let_it_be(:project) { create(:project_with_design, group: group) } + let(:expected_project) { project } + let(:expected_group) { group } it_behaves_like 'Gitaly feature flag actors are inferred from repository' do - let(:repository) { design_repo.repository } + let(:repository) { project.design_repository } end it_behaves_like 'Gitaly feature flag actors are inferred from repository' do - let(:repository) { design_repo.repository.raw } + let(:repository) { project.design_repository.raw } end it_behaves_like 'Gitaly feature flag actors are inferred from repository' do - let(:repository) { raw_repo_without_container(design_repo.repository) } + let(:repository) { raw_repo_without_container(project.design_repository) } end end end |