diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-18 13:34:06 +0300 |
commit | 859a6fb938bb9ee2a317c46dfa4fcc1af49608f0 (patch) | |
tree | d7f2700abe6b4ffcb2dcfc80631b2d87d0609239 /spec/services/ci/pipeline_artifacts | |
parent | 446d496a6d000c73a304be52587cd9bbc7493136 (diff) |
Add latest changes from gitlab-org/gitlab@13-9-stable-eev13.9.0-rc42
Diffstat (limited to 'spec/services/ci/pipeline_artifacts')
-rw-r--r-- | spec/services/ci/pipeline_artifacts/create_code_quality_mr_diff_report_service_spec.rb | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/spec/services/ci/pipeline_artifacts/create_code_quality_mr_diff_report_service_spec.rb b/spec/services/ci/pipeline_artifacts/create_code_quality_mr_diff_report_service_spec.rb new file mode 100644 index 00000000000..0c48f15d726 --- /dev/null +++ b/spec/services/ci/pipeline_artifacts/create_code_quality_mr_diff_report_service_spec.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe ::Ci::PipelineArtifacts::CreateCodeQualityMrDiffReportService do + describe '#execute' do + subject(:pipeline_artifact) { described_class.new.execute(pipeline) } + + context 'when pipeline has codequality reports' do + let(:project) { create(:project, :repository) } + + describe 'pipeline completed status' do + using RSpec::Parameterized::TableSyntax + + where(:status, :result) do + :success | 1 + :failed | 1 + :canceled | 1 + :skipped | 1 + end + + with_them do + let(:pipeline) { create(:ci_pipeline, :with_codequality_reports, status: status, project: project) } + + it 'creates a pipeline artifact' do + expect { pipeline_artifact }.to change(Ci::PipelineArtifact, :count).by(result) + end + + it 'persists the default file name' do + expect(pipeline_artifact.file.filename).to eq('code_quality_mr_diff.json') + end + + it 'sets expire_at to 1 week' do + freeze_time do + expect(pipeline_artifact.expire_at).to eq(1.week.from_now) + end + end + end + end + + context 'when pipeline artifact has already been created' do + let(:pipeline) { create(:ci_pipeline, :with_codequality_reports, project: project) } + + it 'does not persist the same artifact twice' do + 2.times { described_class.new.execute(pipeline) } + + expect(Ci::PipelineArtifact.count).to eq(1) + end + end + end + + context 'when pipeline is not completed and codequality report does not exist' do + let(:pipeline) { create(:ci_pipeline, :running) } + + it 'does not persist data' do + pipeline_artifact + + expect(Ci::PipelineArtifact.count).to eq(0) + end + end + end +end |