1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ci::PipelineArtifacts::CoverageReportService do
describe '#execute' do
let_it_be(:project) { create(:project, :repository) }
subject { described_class.new(pipeline).execute }
shared_examples 'creating or updating a pipeline coverage report' do
context 'when pipeline is finished' do
it 'creates or updates a pipeline artifact' do
subject
expect(pipeline.reload.pipeline_artifacts.count).to eq(1)
end
it 'persists the default file name' do
subject
file = Ci::PipelineArtifact.first.file
expect(file.filename).to eq('code_coverage.json')
end
it 'sets expire_at to 1 week from now' do
freeze_time do
subject
pipeline_artifact = Ci::PipelineArtifact.first
expect(pipeline_artifact.expire_at).to eq(1.week.from_now)
end
end
it 'logs relevant information' do
allow(Gitlab::AppLogger).to receive(:info).and_call_original
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)
})
subject
end
end
end
context 'when pipeline has coverage report' do
let!(:pipeline) { create(:ci_pipeline, :with_coverage_reports, project: project) }
it_behaves_like 'creating or updating a pipeline coverage report'
it "artifact has pipeline's locked status" do
subject
artifact = Ci::PipelineArtifact.first
expect(artifact.locked).to eq(pipeline.locked)
end
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) }
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'
end
context 'when pipeline is running and coverage report does not exist' do
let(:pipeline) { create(:ci_pipeline, :running) }
it 'does not persist data' do
expect { subject }.not_to change { Ci::PipelineArtifact.count }.from(0)
end
end
end
end
|