debian-mirror-gitlab/spec/services/ci/pipeline_artifacts/create_code_quality_mr_diff_report_service_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
3 KiB
Ruby
Raw Normal View History

2021-03-11 19:13:27 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Ci::PipelineArtifacts::CreateCodeQualityMrDiffReportService do
describe '#execute' do
2021-06-08 01:23:25 +05:30
let(:merge_request) { create(:merge_request) }
let(:project) { merge_request.project }
let(:head_pipeline) { create(:ci_pipeline, :success, :with_codequality_reports, project: project, merge_requests_as_head_pipeline: [merge_request]) }
let(:base_pipeline) { create(:ci_pipeline, :success, project: project, ref: merge_request.target_branch, sha: merge_request.diff_base_sha) }
2021-03-11 19:13:27 +05:30
2021-06-08 01:23:25 +05:30
subject { described_class.new(head_pipeline).execute }
2021-03-11 19:13:27 +05:30
2021-06-08 01:23:25 +05:30
context 'when there are codequality reports' do
context 'when pipeline passes' do
context 'when degradations are present' do
context 'when degradations already present in target branch pipeline' do
before do
create(:ci_build, :success, :codequality_reports, name: 'codequality', pipeline: base_pipeline, project: project)
end
2021-03-11 19:13:27 +05:30
2021-06-08 01:23:25 +05:30
it "does not persist a pipeline artifact" do
expect { subject }.not_to change { Ci::PipelineArtifact.count }
end
end
context 'when degradation is not present in target branch pipeline' do
before do
create(:ci_build, :success, :codequality_reports_without_degradation, name: 'codequality', pipeline: base_pipeline, project: project)
end
2021-03-11 19:13:27 +05:30
2021-06-08 01:23:25 +05:30
it 'persists a pipeline artifact' do
expect { subject }.to change { Ci::PipelineArtifact.count }.by(1)
end
2021-03-11 19:13:27 +05:30
2021-06-08 01:23:25 +05:30
it 'persists the default file name' do
subject
2021-03-11 19:13:27 +05:30
2021-06-08 01:23:25 +05:30
pipeline_artifact = Ci::PipelineArtifact.first
2021-03-11 19:13:27 +05:30
2021-06-08 01:23:25 +05:30
expect(pipeline_artifact.file.filename).to eq('code_quality_mr_diff.json')
2021-03-11 19:13:27 +05:30
end
2021-06-08 01:23:25 +05:30
it 'sets expire_at to 1 week' do
freeze_time do
subject
pipeline_artifact = Ci::PipelineArtifact.first
expect(pipeline_artifact.expire_at).to eq(1.week.from_now)
end
end
2021-03-11 19:13:27 +05:30
2021-06-08 01:23:25 +05:30
it 'does not persist the same artifact twice' do
2.times { described_class.new(head_pipeline).execute }
2021-03-11 19:13:27 +05:30
2021-06-08 01:23:25 +05:30
expect { subject }.not_to change { Ci::PipelineArtifact.count }
end
end
2021-03-11 19:13:27 +05:30
end
end
end
2021-06-08 01:23:25 +05:30
context 'when there are no codequality reports for head pipeline' do
let(:head_pipeline) { create(:ci_pipeline, :success, project: project, merge_requests_as_head_pipeline: [merge_request]) }
it "does not persist a pipeline artifact" do
expect { subject }.not_to change { Ci::PipelineArtifact.count }
end
end
2021-03-11 19:13:27 +05:30
2021-06-08 01:23:25 +05:30
context 'when there are no codequality reports for base pipeline' do
let(:head_pipeline) { create(:ci_pipeline, :success, project: project, merge_requests_as_head_pipeline: [merge_request]) }
2021-03-11 19:13:27 +05:30
2021-06-08 01:23:25 +05:30
it "does not persist a pipeline artifact" do
expect { subject }.not_to change { Ci::PipelineArtifact.count }
2021-03-11 19:13:27 +05:30
end
end
end
end