Commit 43d84006 authored by Kerri Miller's avatar Kerri Miller

Merge branch 'mo-refactor-pipeline-artifact-factories' into 'master'

Refactor pipeline artifact factories

See merge request gitlab-org/gitlab!52615
parents 00bed156 7d6cb647
...@@ -308,12 +308,6 @@ FactoryBot.define do ...@@ -308,12 +308,6 @@ FactoryBot.define do
end end
end end
trait :codequality_report do
after(:build) do |build|
build.job_artifacts << create(:ci_job_artifact, :codequality, job: build)
end
end
trait :test_reports do trait :test_reports do
after(:build) do |build| after(:build) do |build|
build.job_artifacts << create(:ci_job_artifact, :junit, job: build) build.job_artifacts << create(:ci_job_artifact, :junit, job: build)
......
...@@ -4,18 +4,30 @@ FactoryBot.define do ...@@ -4,18 +4,30 @@ FactoryBot.define do
factory :ci_pipeline_artifact, class: 'Ci::PipelineArtifact' do factory :ci_pipeline_artifact, class: 'Ci::PipelineArtifact' do
pipeline factory: :ci_pipeline pipeline factory: :ci_pipeline
project { pipeline.project } project { pipeline.project }
file_type { :code_coverage }
file_format { :raw } file_format { :raw }
file_store { ObjectStorage::SUPPORTED_STORES.first } file_store { ObjectStorage::SUPPORTED_STORES.first }
size { 1.megabytes } size { 1.megabyte }
file_type { :code_coverage }
after(:build) do |artifact, _evaluator| after(:build) do |artifact, _evaluator|
artifact.file = fixture_file_upload( artifact.file = fixture_file_upload(
Rails.root.join('spec/fixtures/pipeline_artifacts/code_coverage.json'), 'application/json') Rails.root.join('spec/fixtures/pipeline_artifacts/code_coverage.json'), 'application/json')
end end
trait :with_multibyte_characters do trait :with_coverage_report do
file_type { :code_coverage }
after(:build) do |artifact, _evaluator|
artifact.file = fixture_file_upload(
Rails.root.join('spec/fixtures/pipeline_artifacts/code_coverage.json'), 'application/json')
end
size { file.size }
end
trait :with_coverage_multibyte_characters do
file_type { :code_coverage }
size { { "utf8" => "✓" }.to_json.bytesize } size { { "utf8" => "✓" }.to_json.bytesize }
after(:build) do |artifact, _evaluator| after(:build) do |artifact, _evaluator|
artifact.file = CarrierWaveStringFile.new_file( artifact.file = CarrierWaveStringFile.new_file(
file_content: { "utf8" => "✓" }.to_json, file_content: { "utf8" => "✓" }.to_json,
...@@ -26,23 +38,26 @@ FactoryBot.define do ...@@ -26,23 +38,26 @@ FactoryBot.define do
end end
trait :with_code_coverage_with_multiple_files do trait :with_code_coverage_with_multiple_files do
file_type { :code_coverage }
after(:build) do |artifact, _evaluator| after(:build) do |artifact, _evaluator|
artifact.file = fixture_file_upload( artifact.file = fixture_file_upload(
Rails.root.join('spec/fixtures/pipeline_artifacts/code_coverage_with_multiple_files.json'), 'application/json' Rails.root.join('spec/fixtures/pipeline_artifacts/code_coverage_with_multiple_files.json'), 'application/json'
) )
end end
size { file.size } size { 1.megabyte }
end end
trait :codequality_report do trait :with_codequality_report do
file_type { :code_quality } file_type { :code_quality }
size { 2.megabytes }
after(:build) do |artifact, _evaluator| after(:build) do |artifact, _evaluator|
artifact.file = fixture_file_upload( artifact.file = fixture_file_upload(
Rails.root.join('spec/fixtures/pipeline_artifacts/code_quality.json'), 'application/json') Rails.root.join('spec/fixtures/pipeline_artifacts/code_quality.json'), 'application/json')
end end
size { file.size }
end end
end end
end end
...@@ -93,14 +93,6 @@ FactoryBot.define do ...@@ -93,14 +93,6 @@ FactoryBot.define do
end end
end end
trait :with_codequality_report do
status { :success }
after(:build) do |pipeline, evaluator|
pipeline.builds << build(:ci_build, :codequality_report, pipeline: pipeline, project: pipeline.project)
end
end
trait :with_test_reports do trait :with_test_reports do
status { :success } status { :success }
...@@ -159,13 +151,13 @@ FactoryBot.define do ...@@ -159,13 +151,13 @@ FactoryBot.define do
trait :with_coverage_report_artifact do trait :with_coverage_report_artifact do
after(:build) do |pipeline, evaluator| after(:build) do |pipeline, evaluator|
pipeline.pipeline_artifacts << build(:ci_pipeline_artifact, pipeline: pipeline, project: pipeline.project) pipeline.pipeline_artifacts << build(:ci_pipeline_artifact, :with_coverage_report, pipeline: pipeline, project: pipeline.project)
end end
end end
trait :with_codequality_report_artifact do trait :with_quality_report_artifact do
after(:build) do |pipeline, evaluator| after(:build) do |pipeline, evaluator|
pipeline.pipeline_artifacts << build(:ci_pipeline_artifact, :codequality_report, pipeline: pipeline, project: pipeline.project) pipeline.pipeline_artifacts << build(:ci_pipeline_artifact, :with_codequality_report, pipeline: pipeline, project: pipeline.project)
end end
end end
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Ci::PipelineArtifact, type: :model do RSpec.describe Ci::PipelineArtifact, type: :model do
let(:coverage_report) { create(:ci_pipeline_artifact) } let(:coverage_report) { create(:ci_pipeline_artifact, :with_coverage_report) }
describe 'associations' do describe 'associations' do
it { is_expected.to belong_to(:pipeline) } it { is_expected.to belong_to(:pipeline) }
...@@ -15,7 +15,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do ...@@ -15,7 +15,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do
it_behaves_like 'UpdateProjectStatistics' do it_behaves_like 'UpdateProjectStatistics' do
let_it_be(:pipeline, reload: true) { create(:ci_pipeline) } let_it_be(:pipeline, reload: true) { create(:ci_pipeline) }
subject { build(:ci_pipeline_artifact, pipeline: pipeline) } subject { build(:ci_pipeline_artifact, :with_code_coverage_with_multiple_files, pipeline: pipeline) }
end end
describe 'validations' do describe 'validations' do
...@@ -51,7 +51,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do ...@@ -51,7 +51,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do
end end
describe 'file is being stored' do describe 'file is being stored' do
subject { create(:ci_pipeline_artifact) } subject { create(:ci_pipeline_artifact, :with_coverage_report) }
context 'when existing object has local store' do context 'when existing object has local store' do
it_behaves_like 'mounted file in local store' it_behaves_like 'mounted file in local store'
...@@ -68,7 +68,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do ...@@ -68,7 +68,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do
end end
context 'when file contains multi-byte characters' do context 'when file contains multi-byte characters' do
let(:coverage_report_multibyte) { create(:ci_pipeline_artifact, :with_multibyte_characters) } let(:coverage_report_multibyte) { create(:ci_pipeline_artifact, :with_coverage_multibyte_characters) }
it 'sets the size in bytesize' do it 'sets the size in bytesize' do
expect(coverage_report_multibyte.size).to eq(14) expect(coverage_report_multibyte.size).to eq(14)
...@@ -83,7 +83,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do ...@@ -83,7 +83,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do
let(:file_type) { :code_coverage } let(:file_type) { :code_coverage }
context 'when pipeline artifact has a coverage report' do context 'when pipeline artifact has a coverage report' do
let!(:pipeline_artifact) { create(:ci_pipeline_artifact) } let!(:pipeline_artifact) { create(:ci_pipeline_artifact, :with_coverage_report) }
it 'returns true' do it 'returns true' do
expect(pipeline_artifact).to be_truthy expect(pipeline_artifact).to be_truthy
...@@ -101,7 +101,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do ...@@ -101,7 +101,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do
let(:file_type) { :code_quality } let(:file_type) { :code_quality }
context 'when pipeline artifact has a quality report' do context 'when pipeline artifact has a quality report' do
let!(:pipeline_artifact) { create(:ci_pipeline_artifact, :codequality_report) } let!(:pipeline_artifact) { create(:ci_pipeline_artifact, :with_codequality_report) }
it 'returns true' do it 'returns true' do
expect(pipeline_artifact).to be_truthy expect(pipeline_artifact).to be_truthy
...@@ -131,7 +131,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do ...@@ -131,7 +131,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do
let(:file_type) { :code_coverage } let(:file_type) { :code_coverage }
context 'when pipeline artifact has a coverage report' do context 'when pipeline artifact has a coverage report' do
let!(:coverage_report) { create(:ci_pipeline_artifact) } let!(:coverage_report) { create(:ci_pipeline_artifact, :with_coverage_report) }
it 'returns a pipeline artifact with a coverage report' do it 'returns a pipeline artifact with a coverage report' do
expect(pipeline_artifact.file_type).to eq('code_coverage') expect(pipeline_artifact.file_type).to eq('code_coverage')
...@@ -149,7 +149,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do ...@@ -149,7 +149,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do
let(:file_type) { :code_quality } let(:file_type) { :code_quality }
context 'when pipeline artifact has a quality report' do context 'when pipeline artifact has a quality report' do
let!(:coverage_report) { create(:ci_pipeline_artifact, :codequality_report) } let!(:coverage_report) { create(:ci_pipeline_artifact, :with_codequality_report) }
it 'returns a pipeline artifact with a quality report' do it 'returns a pipeline artifact with a quality report' do
expect(pipeline_artifact.file_type).to eq('code_quality') expect(pipeline_artifact.file_type).to eq('code_quality')
......
...@@ -3388,7 +3388,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do ...@@ -3388,7 +3388,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
describe '#batch_lookup_report_artifact_for_file_type' do describe '#batch_lookup_report_artifact_for_file_type' do
context 'with code quality report artifact' do context 'with code quality report artifact' do
let(:pipeline) { create(:ci_pipeline, :with_codequality_report, project: project) } let(:pipeline) { create(:ci_pipeline, :with_codequality_reports, project: project) }
it "returns the code quality artifact" do it "returns the code quality artifact" do
expect(pipeline.batch_lookup_report_artifact_for_file_type(:codequality)).to eq(pipeline.job_artifacts.sample) expect(pipeline.batch_lookup_report_artifact_for_file_type(:codequality)).to eq(pipeline.job_artifacts.sample)
...@@ -3514,7 +3514,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do ...@@ -3514,7 +3514,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
subject { pipeline.has_codequality_reports? } subject { pipeline.has_codequality_reports? }
context 'when pipeline has a codequality artifact' do context 'when pipeline has a codequality artifact' do
let(:pipeline) { create(:ci_pipeline, :with_codequality_report_artifact, :running, project: project) } let(:pipeline) { create(:ci_pipeline, :with_quality_report_artifact, :running, project: project) }
it { expect(subject).to be_truthy } it { expect(subject).to be_truthy }
end end
......
...@@ -77,7 +77,7 @@ RSpec.describe MergeRequestWidgetEntity do ...@@ -77,7 +77,7 @@ RSpec.describe MergeRequestWidgetEntity do
end end
describe 'codequality report artifacts', :request_store do describe 'codequality report artifacts', :request_store do
let(:merge_base_pipeline) { create(:ci_pipeline, :with_codequality_report, project: project) } let(:merge_base_pipeline) { create(:ci_pipeline, :with_codequality_reports, project: project) }
before do before do
project.add_developer(user) project.add_developer(user)
...@@ -90,7 +90,7 @@ RSpec.describe MergeRequestWidgetEntity do ...@@ -90,7 +90,7 @@ RSpec.describe MergeRequestWidgetEntity do
end end
context 'with report artifacts' do context 'with report artifacts' do
let(:pipeline) { create(:ci_pipeline, :with_codequality_report, project: project) } let(:pipeline) { create(:ci_pipeline, :with_codequality_reports, project: project) }
let(:generic_job_id) { pipeline.builds.first.id } let(:generic_job_id) { pipeline.builds.first.id }
let(:merge_base_job_id) { merge_base_pipeline.builds.first.id } let(:merge_base_job_id) { merge_base_pipeline.builds.first.id }
...@@ -100,7 +100,7 @@ RSpec.describe MergeRequestWidgetEntity do ...@@ -100,7 +100,7 @@ RSpec.describe MergeRequestWidgetEntity do
end end
context 'on pipelines for merged results' do context 'on pipelines for merged results' do
let(:pipeline) { create(:ci_pipeline, :merged_result_pipeline, :with_codequality_report, project: project) } let(:pipeline) { create(:ci_pipeline, :merged_result_pipeline, :with_codequality_reports, project: project) }
it 'returns URLs from the head_pipeline and merge_base_pipeline' do it 'returns URLs from the head_pipeline and merge_base_pipeline' do
expect(subject[:codeclimate][:head_path]).to include("/jobs/#{generic_job_id}/artifacts/download?file_type=codequality") expect(subject[:codeclimate][:head_path]).to include("/jobs/#{generic_job_id}/artifacts/download?file_type=codequality")
......
...@@ -7,7 +7,7 @@ RSpec.describe Ci::PipelineArtifacts::ExpireArtifactsWorker do ...@@ -7,7 +7,7 @@ RSpec.describe Ci::PipelineArtifacts::ExpireArtifactsWorker do
describe '#perform' do describe '#perform' do
let_it_be(:pipeline_artifact) do let_it_be(:pipeline_artifact) do
create(:ci_pipeline_artifact, expire_at: 1.week.ago) create(:ci_pipeline_artifact, :with_coverage_report, expire_at: 1.week.ago)
end end
it 'executes a service' do it 'executes a service' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment