diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 16:49:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-20 16:49:51 +0300 |
commit | 71786ddc8e28fbd3cb3fcc4b3ff15e5962a1c82e (patch) | |
tree | 6a2d93ef3fb2d353bb7739e4b57e6541f51cdd71 /spec/tooling/danger/stable_branch_spec.rb | |
parent | a7253423e3403b8c08f8a161e5937e1488f5f407 (diff) |
Add latest changes from gitlab-org/gitlab@15-9-stable-eev15.9.0-rc42
Diffstat (limited to 'spec/tooling/danger/stable_branch_spec.rb')
-rw-r--r-- | spec/tooling/danger/stable_branch_spec.rb | 137 |
1 files changed, 128 insertions, 9 deletions
diff --git a/spec/tooling/danger/stable_branch_spec.rb b/spec/tooling/danger/stable_branch_spec.rb index 08fd25b30e0..9eee077d493 100644 --- a/spec/tooling/danger/stable_branch_spec.rb +++ b/spec/tooling/danger/stable_branch_spec.rb @@ -12,6 +12,8 @@ RSpec.describe Tooling::Danger::StableBranch, feature_category: :delivery do include_context 'with dangerfile' let(:fake_danger) { DangerSpecHelper.fake_danger.include(described_class) } + let(:fake_api) { double('Api') } # rubocop:disable RSpec/VerifiedDoubles + let(:gitlab_gem_client) { double('gitlab') } # rubocop:disable RSpec/VerifiedDoubles let(:stable_branch) { fake_danger.new(helper: fake_helper) } @@ -34,6 +36,28 @@ RSpec.describe Tooling::Danger::StableBranch, feature_category: :delivery do end end + shared_examples 'with a warning' do |warning_message| + it 'warns' do + expect(stable_branch).to receive(:warn).with(warning_message) + + subject + end + end + + shared_examples 'bypassing when flaky test or docs only' do + context 'when failure::flaky-test label is present' do + let(:flaky_test_label_present) { true } + + it_behaves_like 'without a failure' + end + + context 'with only docs changes' do + let(:changes_by_category_response) { { docs: ['foo.md'] } } + + it_behaves_like 'without a failure' + end + end + context 'when not applicable' do where(:stable_branch?, :security_mr?) do true | true @@ -47,15 +71,32 @@ RSpec.describe Tooling::Danger::StableBranch, feature_category: :delivery do allow(fake_helper).to receive(:security_mr?).and_return(security_mr?) end - it_behaves_like "without a failure" + it_behaves_like 'without a failure' end end context 'when applicable' do let(:target_branch) { '15-1-stable-ee' } + let(:source_branch) { 'my_bug_branch' } let(:feature_label_present) { false } let(:bug_label_present) { true } + let(:pipeline_expedite_label_present) { false } + let(:flaky_test_label_present) { false } let(:response_success) { true } + + let(:changes_by_category_response) do + { + graphql: ['bar.rb'] + } + end + + let(:pipeline_bridges_response) do + [ + { 'name' => 'e2e:package-and-test', + 'status' => 'success' } + ] + end + let(:parsed_response) do [ { 'version' => '15.1.1' }, @@ -79,14 +120,27 @@ RSpec.describe Tooling::Danger::StableBranch, feature_category: :delivery do before do allow(fake_helper).to receive(:mr_target_branch).and_return(target_branch) + allow(fake_helper).to receive(:mr_source_branch).and_return(source_branch) allow(fake_helper).to receive(:security_mr?).and_return(false) + allow(fake_helper).to receive(:mr_target_project_id).and_return(1) allow(fake_helper).to receive(:mr_has_labels?).with('type::feature').and_return(feature_label_present) allow(fake_helper).to receive(:mr_has_labels?).with('type::bug').and_return(bug_label_present) + allow(fake_helper).to receive(:mr_has_labels?).with('pipeline:expedite') + .and_return(pipeline_expedite_label_present) + allow(fake_helper).to receive(:mr_has_labels?).with('failure::flaky-test') + .and_return(flaky_test_label_present) + allow(fake_helper).to receive(:changes_by_category).and_return(changes_by_category_response) allow(HTTParty).to receive(:get).with(/page=1/).and_return(version_response) + allow(fake_helper).to receive(:api).and_return(fake_api) + allow(stable_branch).to receive(:gitlab).and_return(gitlab_gem_client) + allow(gitlab_gem_client).to receive(:mr_json).and_return({ 'head_pipeline' => { 'id' => '1' } }) + allow(gitlab_gem_client).to receive(:api).and_return(fake_api) + allow(fake_api).to receive(:pipeline_bridges).with(1, '1') + .and_return(pipeline_bridges_response) end # the stubbed behavior above is the success path - it_behaves_like "without a failure" + it_behaves_like 'without a failure' context 'with a feature label' do let(:feature_label_present) { true } @@ -100,20 +154,65 @@ RSpec.describe Tooling::Danger::StableBranch, feature_category: :delivery do it_behaves_like 'with a failure', described_class::BUG_ERROR_MESSAGE end + context 'with a pipeline:expedite label' do + let(:pipeline_expedite_label_present) { true } + + it_behaves_like 'with a failure', described_class::PIPELINE_EXPEDITE_ERROR_MESSAGE + it_behaves_like 'bypassing when flaky test or docs only' + end + + context 'when no package-and-test job is found' do + let(:pipeline_bridges_response) { nil } + + it_behaves_like 'with a failure', described_class::NEEDS_PACKAGE_AND_TEST_MESSAGE + it_behaves_like 'bypassing when flaky test or docs only' + end + + context 'when package-and-test job is in manual state' do + described_class::FAILING_PACKAGE_AND_TEST_STATUSES.each do |status| + let(:pipeline_bridges_response) do + [ + { 'name' => 'e2e:package-and-test', + 'status' => status } + ] + end + + it_behaves_like 'with a failure', described_class::NEEDS_PACKAGE_AND_TEST_MESSAGE + it_behaves_like 'bypassing when flaky test or docs only' + end + end + + context 'when package-and-test job is in a non-successful state' do + let(:pipeline_bridges_response) do + [ + { 'name' => 'e2e:package-and-test', + 'status' => 'running' } + ] + end + + it_behaves_like 'with a warning', described_class::WARN_PACKAGE_AND_TEST_MESSAGE + it_behaves_like 'bypassing when flaky test or docs only' + end + + context 'when no pipeline is found' do + before do + allow(gitlab_gem_client).to receive(:mr_json).and_return({}) + end + + it_behaves_like 'with a failure', described_class::NEEDS_PACKAGE_AND_TEST_MESSAGE + it_behaves_like 'bypassing when flaky test or docs only' + end + context 'when not an applicable version' do let(:target_branch) { '14-9-stable-ee' } - it_behaves_like 'with a failure', described_class::VERSION_ERROR_MESSAGE + it_behaves_like 'with a warning', described_class::VERSION_WARNING_MESSAGE end context 'when the version API request fails' do let(:response_success) { false } - it 'adds a warning' do - expect(stable_branch).to receive(:warn).with(described_class::FAILED_VERSION_REQUEST_MESSAGE) - - subject - end + it_behaves_like 'with a warning', described_class::FAILED_VERSION_REQUEST_MESSAGE end context 'when more than one page of versions is needed' do @@ -151,7 +250,7 @@ RSpec.describe Tooling::Danger::StableBranch, feature_category: :delivery do allow(HTTParty).to receive(:get).with(/page=2/).and_return(second_version_response) end - it_behaves_like "without a failure" + it_behaves_like 'without a failure' end context 'when too many version API requests are made' do @@ -166,4 +265,24 @@ RSpec.describe Tooling::Danger::StableBranch, feature_category: :delivery do end end end + + describe '#non_security_stable_branch?' do + subject { stable_branch.non_security_stable_branch? } + + where(:stable_branch?, :security_mr?, :expected_result) do + true | true | false + false | true | false + true | false | true + false | false | false + end + + with_them do + before do + allow(fake_helper).to receive(:mr_target_branch).and_return(stable_branch? ? '15-1-stable-ee' : 'main') + allow(fake_helper).to receive(:security_mr?).and_return(security_mr?) + end + + it { is_expected.to eq(expected_result) } + end + end end |