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

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

67 lines
2 KiB
Ruby
Raw Normal View History

2020-11-24 15:15:51 +05:30
# frozen_string_literal: true
require 'spec_helper'
2021-03-08 18:12:59 +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-07-23 23:45:48 +05:30
shared_examples 'creating a pipeline coverage report' do
2020-11-24 15:15:51 +05:30
context 'when pipeline is finished' do
it 'creates a pipeline artifact' do
2022-07-23 23:45:48 +05:30
expect { subject }.to change { Ci::PipelineArtifact.count }.from(0).to(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
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
end
context 'when pipeline artifact has already been created' do
2022-07-23 23:45:48 +05:30
it 'does not raise an error and does not persist the same artifact twice' do
expect { 2.times { described_class.new(pipeline).execute } }.not_to raise_error
2020-11-24 15:15:51 +05:30
expect(Ci::PipelineArtifact.count).to eq(1)
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) }
it_behaves_like 'creating a pipeline coverage report'
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 a pipeline coverage report'
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-07-23 23:45:48 +05:30
expect { subject }.not_to change { Ci::PipelineArtifact.count }
2020-11-24 15:15:51 +05:30
end
end
end
end