Commit 7d6cb647 authored by Maxime Orefice's avatar Maxime Orefice

Refactor pipeline artifact factories

This commit refactors our pipeline artifact factories.
It removes duplicates and renames some factories to be consistent
with existing ones.
parent 37a2e335
......@@ -308,12 +308,6 @@ FactoryBot.define do
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
after(:build) do |build|
build.job_artifacts << create(:ci_job_artifact, :junit, job: build)
......
......@@ -4,18 +4,30 @@ FactoryBot.define do
factory :ci_pipeline_artifact, class: 'Ci::PipelineArtifact' do
pipeline factory: :ci_pipeline
project { pipeline.project }
file_type { :code_coverage }
file_format { :raw }
file_store { ObjectStorage::SUPPORTED_STORES.first }
size { 1.megabytes }
size { 1.megabyte }
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
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
trait :with_multibyte_characters do
size { file.size }
end
trait :with_coverage_multibyte_characters do
file_type { :code_coverage }
size { { "utf8" => "✓" }.to_json.bytesize }
after(:build) do |artifact, _evaluator|
artifact.file = CarrierWaveStringFile.new_file(
file_content: { "utf8" => "✓" }.to_json,
......@@ -26,23 +38,26 @@ FactoryBot.define do
end
trait :with_code_coverage_with_multiple_files do
file_type { :code_coverage }
after(:build) do |artifact, _evaluator|
artifact.file = fixture_file_upload(
Rails.root.join('spec/fixtures/pipeline_artifacts/code_coverage_with_multiple_files.json'), 'application/json'
)
end
size { file.size }
size { 1.megabyte }
end
trait :codequality_report do
trait :with_codequality_report do
file_type { :code_quality }
size { 2.megabytes }
after(:build) do |artifact, _evaluator|
artifact.file = fixture_file_upload(
Rails.root.join('spec/fixtures/pipeline_artifacts/code_quality.json'), 'application/json')
end
size { file.size }
end
end
end
......@@ -93,14 +93,6 @@ FactoryBot.define do
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
status { :success }
......@@ -159,13 +151,13 @@ FactoryBot.define do
trait :with_coverage_report_artifact do
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
trait :with_codequality_report_artifact do
trait :with_quality_report_artifact do
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
......
......@@ -3,7 +3,7 @@
require 'spec_helper'
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
it { is_expected.to belong_to(:pipeline) }
......@@ -15,7 +15,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do
it_behaves_like 'UpdateProjectStatistics' do
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
describe 'validations' do
......@@ -51,7 +51,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do
end
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
it_behaves_like 'mounted file in local store'
......@@ -68,7 +68,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do
end
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
expect(coverage_report_multibyte.size).to eq(14)
......@@ -83,7 +83,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do
let(:file_type) { :code_coverage }
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
expect(pipeline_artifact).to be_truthy
......@@ -101,7 +101,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do
let(:file_type) { :code_quality }
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
expect(pipeline_artifact).to be_truthy
......@@ -131,7 +131,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do
let(:file_type) { :code_coverage }
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
expect(pipeline_artifact.file_type).to eq('code_coverage')
......@@ -149,7 +149,7 @@ RSpec.describe Ci::PipelineArtifact, type: :model do
let(:file_type) { :code_quality }
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
expect(pipeline_artifact.file_type).to eq('code_quality')
......
......@@ -3388,7 +3388,7 @@ RSpec.describe Ci::Pipeline, :mailer, factory_default: :keep do
describe '#batch_lookup_report_artifact_for_file_type' 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
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
subject { pipeline.has_codequality_reports? }
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 }
end
......
......@@ -77,7 +77,7 @@ RSpec.describe MergeRequestWidgetEntity do
end
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
project.add_developer(user)
......@@ -90,7 +90,7 @@ RSpec.describe MergeRequestWidgetEntity do
end
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(:merge_base_job_id) { merge_base_pipeline.builds.first.id }
......@@ -100,7 +100,7 @@ RSpec.describe MergeRequestWidgetEntity do
end
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
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
describe '#perform' 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
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