diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-06 15:06:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-07-06 15:06:46 +0300 |
commit | 30acb0522a609c438d60f5345243e96f9a041ae6 (patch) | |
tree | ce1b11d55c510996e3ebe9a5e96db5fd08dbeaf2 /spec/services | |
parent | d2485dbfedc4759eba5243e0d155e34494c4429b (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services')
4 files changed, 14 insertions, 201 deletions
diff --git a/spec/services/auto_merge/merge_when_pipeline_succeeds_service_spec.rb b/spec/services/auto_merge/merge_when_pipeline_succeeds_service_spec.rb index a0b22267960..79c931990bb 100644 --- a/spec/services/auto_merge/merge_when_pipeline_succeeds_service_spec.rb +++ b/spec/services/auto_merge/merge_when_pipeline_succeeds_service_spec.rb @@ -3,30 +3,7 @@ require 'spec_helper' RSpec.describe AutoMerge::MergeWhenPipelineSucceedsService, feature_category: :code_review_workflow do - let_it_be(:user) { create(:user) } - let_it_be(:project) { create(:project, :repository) } - - let(:mr_merge_if_green_enabled) do - create(:merge_request, merge_when_pipeline_succeeds: true, merge_user: user, - source_branch: "master", target_branch: 'feature', - source_project: project, target_project: project, state: "opened") - end - - let(:pipeline) do - create(:ci_pipeline, ref: mr_merge_if_green_enabled.source_branch, project: project) - end - - let(:service) do - described_class.new(project, user, commit_message: 'Awesome message') - end - - before_all do - project.add_maintainer(user) - end - - before do - allow(MergeWorker).to receive(:with_status).and_return(MergeWorker) - end + include_context 'for auto_merge strategy context' describe "#available_for?" do subject { service.available_for?(mr_merge_if_green_enabled) } @@ -64,152 +41,24 @@ RSpec.describe AutoMerge::MergeWhenPipelineSucceedsService, feature_category: :c end describe "#execute" do - let(:merge_request) do - create(:merge_request, target_project: project, source_project: project, - source_branch: "feature", target_branch: 'master') - end - - context 'first time enabling' do - before do - allow(merge_request) - .to receive_messages(head_pipeline: pipeline, actual_head_pipeline: pipeline) - expect(MailScheduler::NotificationServiceWorker).to receive(:perform_async).with('merge_when_pipeline_succeeds', merge_request, user).once - - service.execute(merge_request) - end - - it 'sets the params, merge_user, and flag' do - expect(merge_request).to be_valid - expect(merge_request.merge_when_pipeline_succeeds).to be_truthy - expect(merge_request.merge_params).to include 'commit_message' => 'Awesome message' - expect(merge_request.merge_user).to be user - expect(merge_request.auto_merge_strategy).to eq AutoMergeService::STRATEGY_MERGE_WHEN_PIPELINE_SUCCEEDS - end - - it 'creates a system note' do - pipeline = build(:ci_pipeline) - allow(merge_request).to receive(:actual_head_pipeline) { pipeline } - - note = merge_request.notes.last - expect(note.note).to match "enabled an automatic merge when the pipeline for #{pipeline.sha}" - end - end - - context 'already approved' do - let(:service) { described_class.new(project, user, should_remove_source_branch: true) } - let(:build) { create(:ci_build, ref: mr_merge_if_green_enabled.source_branch) } - - before do - allow(mr_merge_if_green_enabled) - .to receive_messages(head_pipeline: pipeline, actual_head_pipeline: pipeline) - - allow(mr_merge_if_green_enabled).to receive(:mergeable?) - .and_return(true) - - allow(pipeline).to receive(:success?).and_return(true) - end - - it 'updates the merge params' do - expect(SystemNoteService).not_to receive(:merge_when_pipeline_succeeds) - expect(MailScheduler::NotificationServiceWorker).not_to receive(:perform_async).with('merge_when_pipeline_succeeds', any_args) - - service.execute(mr_merge_if_green_enabled) - expect(mr_merge_if_green_enabled.merge_params).to have_key('should_remove_source_branch') + it_behaves_like 'auto_merge service #execute', 'merge_when_pipeline_succeeds' do + let(:auto_merge_strategy) { AutoMergeService::STRATEGY_MERGE_WHEN_PIPELINE_SUCCEEDS } + let(:expected_note) do + "enabled an automatic merge when the pipeline for #{pipeline.sha}" end end end describe "#process" do - let(:merge_request_ref) { mr_merge_if_green_enabled.source_branch } - let(:merge_request_head) do - project.commit(mr_merge_if_green_enabled.source_branch).id - end - - context 'when triggered by pipeline with valid ref and sha' do - let(:triggering_pipeline) do - create(:ci_pipeline, project: project, ref: merge_request_ref, - sha: merge_request_head, status: 'success', - head_pipeline_of: mr_merge_if_green_enabled) - end - - it "merges all merge requests with merge when the pipeline succeeds enabled" do - allow(mr_merge_if_green_enabled) - .to receive_messages(head_pipeline: triggering_pipeline, actual_head_pipeline: triggering_pipeline) - - expect(MergeWorker).to receive(:perform_async) - service.process(mr_merge_if_green_enabled) - end - end - - context 'when triggered by an old pipeline' do - let(:old_pipeline) do - create(:ci_pipeline, project: project, ref: merge_request_ref, - sha: '1234abcdef', status: 'success') - end - - it 'does not merge request' do - expect(MergeWorker).not_to receive(:perform_async) - service.process(mr_merge_if_green_enabled) - end - end - - context 'when triggered by pipeline from a different branch' do - let(:unrelated_pipeline) do - create(:ci_pipeline, project: project, ref: 'feature', - sha: merge_request_head, status: 'success') - end - - it 'does not merge request' do - expect(MergeWorker).not_to receive(:perform_async) - service.process(mr_merge_if_green_enabled) - end - end - - context 'when pipeline is merge request pipeline' do - let(:pipeline) do - create(:ci_pipeline, :success, - source: :merge_request_event, - ref: mr_merge_if_green_enabled.merge_ref_path, - merge_request: mr_merge_if_green_enabled, - merge_requests_as_head_pipeline: [mr_merge_if_green_enabled]) - end - - it 'merges the associated merge request' do - allow(mr_merge_if_green_enabled) - .to receive_messages(head_pipeline: pipeline, actual_head_pipeline: pipeline) - - expect(MergeWorker).to receive(:perform_async) - service.process(mr_merge_if_green_enabled) - end - end + it_behaves_like 'auto_merge service #process' end - describe "#cancel" do - before do - service.cancel(mr_merge_if_green_enabled) - end - - it "resets all the pipeline succeeds params" do - expect(mr_merge_if_green_enabled.merge_when_pipeline_succeeds).to be_falsey - expect(mr_merge_if_green_enabled.merge_params).to eq({}) - expect(mr_merge_if_green_enabled.merge_user).to be nil - end - - it 'posts a system note' do - note = mr_merge_if_green_enabled.notes.last - expect(note.note).to include 'canceled the automatic merge' - end + describe '#cancel' do + it_behaves_like 'auto_merge service #cancel' end - describe "#abort" do - before do - service.abort(mr_merge_if_green_enabled, 'an error') - end - - it 'posts a system note' do - note = mr_merge_if_green_enabled.notes.last - expect(note.note).to include 'aborted the automatic merge' - end + describe '#abort' do + it_behaves_like 'auto_merge service #abort' end describe 'pipeline integration' do diff --git a/spec/services/ci/create_pipeline_service/rules_spec.rb b/spec/services/ci/create_pipeline_service/rules_spec.rb index 87112137675..a81d1487fab 100644 --- a/spec/services/ci/create_pipeline_service/rules_spec.rb +++ b/spec/services/ci/create_pipeline_service/rules_spec.rb @@ -452,42 +452,6 @@ RSpec.describe Ci::CreatePipelineService, :yaml_processor_feature_flag_corectnes expect(job4.needs).to contain_exactly(an_object_having_attributes(name: 'job3')) end end - - context 'when the FF introduce_rules_with_needs is disabled' do - before do - stub_feature_flags(introduce_rules_with_needs: false) - end - - context 'when the `$var` rule matches' do - it 'creates a pipeline without overridden needs' do - expect(pipeline).to be_persisted - expect(build_names).to contain_exactly('job1', 'job2', 'job3', 'job4') - - expect(job1.needs).to be_empty - expect(job2.needs).to be_empty - expect(job3.needs).to be_empty - expect(job4.needs).to contain_exactly(an_object_having_attributes(name: 'job1')) - end - end - - context 'when the `$var` rule does not match' do - let(:initialization_params) { base_initialization_params.merge(variables_attributes: variables_attributes) } - - let(:variables_attributes) do - [{ key: 'var', secret_value: 'SOME_VAR' }] - end - - it 'creates a pipeline without overridden needs' do - expect(pipeline).to be_persisted - expect(build_names).to contain_exactly('job1', 'job2', 'job3', 'job4') - - expect(job1.needs).to be_empty - expect(job2.needs).to be_empty - expect(job3.needs).to be_empty - expect(job4.needs).to contain_exactly(an_object_having_attributes(name: 'job1')) - end - end - end end end diff --git a/spec/services/ci/pipeline_trigger_service_spec.rb b/spec/services/ci/pipeline_trigger_service_spec.rb index b6e07e82bb5..fbd1a765351 100644 --- a/spec/services/ci/pipeline_trigger_service_spec.rb +++ b/spec/services/ci/pipeline_trigger_service_spec.rb @@ -23,8 +23,8 @@ RSpec.describe Ci::PipelineTriggerService, feature_category: :continuous_integra shared_examples 'detecting an unprocessable pipeline trigger' do context 'when the pipeline was not created successfully' do let(:fail_pipeline) do - receive(:execute).and_wrap_original do |original, *args| - response = original.call(*args) + receive(:execute).and_wrap_original do |original, *args, **kwargs| + response = original.call(*args, **kwargs) pipeline = response.payload pipeline.update!(failure_reason: 'unknown_failure') diff --git a/spec/services/packages/cleanup/execute_policy_service_spec.rb b/spec/services/packages/cleanup/execute_policy_service_spec.rb index a083dc0d4ea..249fd50588f 100644 --- a/spec/services/packages/cleanup/execute_policy_service_spec.rb +++ b/spec/services/packages/cleanup/execute_policy_service_spec.rb @@ -122,13 +122,13 @@ RSpec.describe Packages::Cleanup::ExecutePolicyService, feature_category: :packa def mock_service_timeout(on_iteration:) execute_call_count = 1 expect_next_instances_of(::Packages::MarkPackageFilesForDestructionService, 3) do |service| - expect(service).to receive(:execute).and_wrap_original do |m, *args| + expect(service).to receive(:execute).and_wrap_original do |m, *args, **kwargs| # timeout if we are on the right iteration if execute_call_count == on_iteration service_timeout_response else execute_call_count += 1 - m.call(*args) + m.call(*args, **kwargs) end end end |