diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 14:34:42 +0000 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /spec/models/ci/pipeline_spec.rb | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) | |
download | gitlab-ce-9f46488805e86b1bc341ea1620b866016c2ce5ed.tar.gz |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'spec/models/ci/pipeline_spec.rb')
-rw-r--r-- | spec/models/ci/pipeline_spec.rb | 145 |
1 files changed, 140 insertions, 5 deletions
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 90412136c1d..4f53b6b4418 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -53,6 +53,29 @@ describe Ci::Pipeline, :mailer do end end + describe '#set_status' do + where(:from_status, :to_status) do + from_status_names = described_class.state_machines[:status].states.map(&:name) + to_status_names = from_status_names - [:created] # we never want to transition into created + + from_status_names.product(to_status_names) + end + + with_them do + it do + pipeline.status = from_status.to_s + + if from_status != to_status + expect(pipeline.set_status(to_status.to_s)) + .to eq(true) + else + expect(pipeline.set_status(to_status.to_s)) + .to eq(false), "loopback transitions are not allowed" + end + end + end + end + describe '.processables' do before do create(:ci_build, name: 'build', pipeline: pipeline) @@ -364,6 +387,26 @@ describe Ci::Pipeline, :mailer do end end + context 'when pipeline has an accessibility report' do + subject { described_class.with_reports(Ci::JobArtifact.accessibility_reports) } + + let(:pipeline_with_report) { create(:ci_pipeline, :with_accessibility_reports) } + + it 'selects the pipeline' do + is_expected.to eq([pipeline_with_report]) + end + end + + context 'when pipeline has a terraform report' do + it 'selects the pipeline' do + pipeline_with_report = create(:ci_pipeline, :with_terraform_reports) + + expect(described_class.with_reports(Ci::JobArtifact.terraform_reports)).to eq( + [pipeline_with_report] + ) + end + end + context 'when pipeline does not have metrics reports' do subject { described_class.with_reports(Ci::JobArtifact.test_reports) } @@ -699,6 +742,28 @@ describe Ci::Pipeline, :mailer do ) end end + + describe 'variable CI_KUBERNETES_ACTIVE' do + context 'when pipeline.has_kubernetes_active? is true' do + before do + allow(pipeline).to receive(:has_kubernetes_active?).and_return(true) + end + + it "is included with value 'true'" do + expect(subject.to_hash).to include('CI_KUBERNETES_ACTIVE' => 'true') + end + end + + context 'when pipeline.has_kubernetes_active? is false' do + before do + allow(pipeline).to receive(:has_kubernetes_active?).and_return(false) + end + + it 'is not included' do + expect(subject.to_hash).not_to have_key('CI_KUBERNETES_ACTIVE') + end + end + end end describe '#protected_ref?' do @@ -944,7 +1009,10 @@ describe Ci::Pipeline, :mailer do context 'when using legacy stages' do before do - stub_feature_flags(ci_pipeline_persisted_stages: false) + stub_feature_flags( + ci_pipeline_persisted_stages: false, + ci_atomic_processing: false + ) end it 'returns legacy stages in valid order' do @@ -952,9 +1020,40 @@ describe Ci::Pipeline, :mailer do end end + context 'when using atomic processing' do + before do + stub_feature_flags( + ci_atomic_processing: true + ) + end + + context 'when pipelines is not complete' do + it 'returns stages in valid order' do + expect(subject).to all(be_a Ci::Stage) + expect(subject.map(&:name)) + .to eq %w[sanity build test deploy cleanup] + end + end + + context 'when pipeline is complete' do + before do + pipeline.succeed! + end + + it 'returns stages in valid order' do + expect(subject).to all(be_a Ci::Stage) + expect(subject.map(&:name)) + .to eq %w[sanity build test deploy cleanup] + end + end + end + context 'when using persisted stages' do before do - stub_feature_flags(ci_pipeline_persisted_stages: true) + stub_feature_flags( + ci_pipeline_persisted_stages: true, + ci_atomic_processing: false + ) end context 'when pipelines is not complete' do @@ -1119,8 +1218,8 @@ describe Ci::Pipeline, :mailer do context "from #{status}" do let(:from_status) { status } - it 'schedules pipeline success worker' do - expect(Ci::DailyReportResultsWorker).to receive(:perform_in).with(10.minutes, pipeline.id) + it 'schedules daily build group report results worker' do + expect(Ci::DailyBuildGroupReportResultsWorker).to receive(:perform_in).with(10.minutes, pipeline.id) pipeline.succeed end @@ -2307,7 +2406,7 @@ describe Ci::Pipeline, :mailer do def have_requested_pipeline_hook(status) have_requested(:post, stubbed_hostname(hook.url)).with do |req| - json_body = JSON.parse(req.body) + json_body = Gitlab::Json.parse(req.body) json_body['object_attributes']['status'] == status && json_body['builds'].length == 2 end @@ -2755,6 +2854,42 @@ describe Ci::Pipeline, :mailer do end end + describe '#accessibility_reports' do + subject { pipeline.accessibility_reports } + + context 'when pipeline has multiple builds with accessibility reports' do + let(:build_rspec) { create(:ci_build, :success, name: 'rspec', pipeline: pipeline, project: project) } + let(:build_golang) { create(:ci_build, :success, name: 'golang', pipeline: pipeline, project: project) } + + before do + create(:ci_job_artifact, :accessibility, job: build_rspec, project: project) + create(:ci_job_artifact, :accessibility_without_errors, job: build_golang, project: project) + end + + it 'returns accessibility report with collected data' do + expect(subject.urls.keys).to match_array([ + "https://pa11y.org/", + "https://about.gitlab.com/" + ]) + end + + context 'when builds are retried' do + let(:build_rspec) { create(:ci_build, :retried, :success, name: 'rspec', pipeline: pipeline, project: project) } + let(:build_golang) { create(:ci_build, :retried, :success, name: 'golang', pipeline: pipeline, project: project) } + + it 'returns empty urls for accessibility reports' do + expect(subject.urls).to be_empty + end + end + end + + context 'when pipeline does not have any builds with accessibility reports' do + it 'returns empty urls for accessibility reports' do + expect(subject.urls).to be_empty + end + end + end + describe '#coverage_reports' do subject { pipeline.coverage_reports } |