2020-11-24 15:15:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
RSpec.describe Ci::PipelineArtifacts::CoverageReportService do
|
2020-11-24 15:15:51 +05:30
|
|
|
describe '#execute' do
|
2022-07-23 23:45:48 +05:30
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
subject { described_class.new(pipeline).execute }
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
shared_examples 'creating or updating a pipeline coverage report' do
|
2020-11-24 15:15:51 +05:30
|
|
|
context 'when pipeline is finished' do
|
2022-08-13 15:12:31 +05:30
|
|
|
it 'creates or updates a pipeline artifact' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(pipeline.reload.pipeline_artifacts.count).to eq(1)
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'persists the default file name' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
file = Ci::PipelineArtifact.first.file
|
|
|
|
|
|
|
|
expect(file.filename).to eq('code_coverage.json')
|
|
|
|
end
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
it 'sets expire_at to 1 week from now' do
|
2020-11-24 15:15:51 +05:30
|
|
|
freeze_time do
|
|
|
|
subject
|
|
|
|
|
|
|
|
pipeline_artifact = Ci::PipelineArtifact.first
|
|
|
|
|
|
|
|
expect(pipeline_artifact.expire_at).to eq(1.week.from_now)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
it 'logs relevant information' do
|
|
|
|
expect(Gitlab::AppLogger).to receive(:info).with({
|
|
|
|
project_id: project.id,
|
|
|
|
pipeline_id: pipeline.id,
|
|
|
|
pipeline_artifact_id: kind_of(Numeric),
|
|
|
|
message: kind_of(String)
|
|
|
|
})
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
subject
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
context 'when pipeline has coverage report' do
|
|
|
|
let!(:pipeline) { create(:ci_pipeline, :with_coverage_reports, project: project) }
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
it_behaves_like 'creating or updating a pipeline coverage report'
|
2022-07-23 23:45:48 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pipeline has coverage report from child pipeline' do
|
|
|
|
let!(:pipeline) { create(:ci_pipeline, :success, project: project) }
|
|
|
|
let!(:child_pipeline) { create(:ci_pipeline, :with_coverage_reports, project: project, child_of: pipeline) }
|
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
it_behaves_like 'creating or updating a pipeline coverage report'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pipeline has existing pipeline artifact for coverage report' do
|
|
|
|
let!(:pipeline) { create(:ci_pipeline, :with_coverage_reports, project: project) }
|
|
|
|
let!(:child_pipeline) { create(:ci_pipeline, :with_coverage_reports, project: project, child_of: pipeline) }
|
|
|
|
|
|
|
|
let!(:pipeline_artifact) do
|
|
|
|
create(:ci_pipeline_artifact, :with_coverage_report, pipeline: pipeline, expire_at: 1.day.from_now)
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'creating or updating a pipeline coverage report'
|
2022-07-23 23:45:48 +05:30
|
|
|
end
|
|
|
|
|
2020-11-24 15:15:51 +05:30
|
|
|
context 'when pipeline is running and coverage report does not exist' do
|
|
|
|
let(:pipeline) { create(:ci_pipeline, :running) }
|
|
|
|
|
|
|
|
it 'does not persist data' do
|
2022-08-13 15:12:31 +05:30
|
|
|
expect { subject }.not_to change { Ci::PipelineArtifact.count }.from(0)
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|