diff options
Diffstat (limited to 'spec/models/ci/job_artifact_spec.rb')
-rw-r--r-- | spec/models/ci/job_artifact_spec.rb | 132 |
1 files changed, 80 insertions, 52 deletions
diff --git a/spec/models/ci/job_artifact_spec.rb b/spec/models/ci/job_artifact_spec.rb index b996bf84529..098f8bd4514 100644 --- a/spec/models/ci/job_artifact_spec.rb +++ b/spec/models/ci/job_artifact_spec.rb @@ -8,6 +8,8 @@ RSpec.describe Ci::JobArtifact do describe "Associations" do it { is_expected.to belong_to(:project) } it { is_expected.to belong_to(:job) } + it { is_expected.to validate_presence_of(:job) } + it { is_expected.to validate_presence_of(:partition_id) } end it { is_expected.to respond_to(:file) } @@ -48,82 +50,86 @@ RSpec.describe Ci::JobArtifact do end end - describe '.test_reports' do - subject { described_class.test_reports } + describe '.of_report_type' do + subject { described_class.of_report_type(report_type) } - context 'when there is a test report' do - let!(:artifact) { create(:ci_job_artifact, :junit) } + describe 'test_reports' do + let(:report_type) { :test } - it { is_expected.to eq([artifact]) } - end + context 'when there is a test report' do + let!(:artifact) { create(:ci_job_artifact, :junit) } - context 'when there are no test reports' do - let!(:artifact) { create(:ci_job_artifact, :archive) } + it { is_expected.to eq([artifact]) } + end - it { is_expected.to be_empty } + context 'when there are no test reports' do + let!(:artifact) { create(:ci_job_artifact, :archive) } + + it { is_expected.to be_empty } + end end - end - describe '.accessibility_reports' do - subject { described_class.accessibility_reports } + describe 'accessibility_reports' do + let(:report_type) { :accessibility } - context 'when there is an accessibility report' do - let(:artifact) { create(:ci_job_artifact, :accessibility) } + context 'when there is an accessibility report' do + let(:artifact) { create(:ci_job_artifact, :accessibility) } - it { is_expected.to eq([artifact]) } - end + it { is_expected.to eq([artifact]) } + end - context 'when there are no accessibility report' do - let(:artifact) { create(:ci_job_artifact, :archive) } + context 'when there are no accessibility report' do + let(:artifact) { create(:ci_job_artifact, :archive) } - it { is_expected.to be_empty } + it { is_expected.to be_empty } + end end - end - describe '.coverage_reports' do - subject { described_class.coverage_reports } + describe 'coverage_reports' do + let(:report_type) { :coverage } - context 'when there is a coverage report' do - let!(:artifact) { create(:ci_job_artifact, :cobertura) } + context 'when there is a coverage report' do + let!(:artifact) { create(:ci_job_artifact, :cobertura) } - it { is_expected.to eq([artifact]) } - end + it { is_expected.to eq([artifact]) } + end - context 'when there are no coverage reports' do - let!(:artifact) { create(:ci_job_artifact, :archive) } + context 'when there are no coverage reports' do + let!(:artifact) { create(:ci_job_artifact, :archive) } - it { is_expected.to be_empty } + it { is_expected.to be_empty } + end end - end - describe '.codequality_reports' do - subject { described_class.codequality_reports } + describe 'codequality_reports' do + let(:report_type) { :codequality } - context 'when there is a codequality report' do - let!(:artifact) { create(:ci_job_artifact, :codequality) } + context 'when there is a codequality report' do + let!(:artifact) { create(:ci_job_artifact, :codequality) } - it { is_expected.to eq([artifact]) } - end + it { is_expected.to eq([artifact]) } + end - context 'when there are no codequality reports' do - let!(:artifact) { create(:ci_job_artifact, :archive) } + context 'when there are no codequality reports' do + let!(:artifact) { create(:ci_job_artifact, :archive) } - it { is_expected.to be_empty } + it { is_expected.to be_empty } + end end - end - describe '.terraform_reports' do - context 'when there is a terraform report' do - it 'return the job artifact' do - artifact = create(:ci_job_artifact, :terraform) + describe 'terraform_reports' do + let(:report_type) { :terraform } + + context 'when there is a terraform report' do + let!(:artifact) { create(:ci_job_artifact, :terraform) } - expect(described_class.terraform_reports).to eq([artifact]) + it { is_expected.to eq([artifact]) } end - end - context 'when there are no terraform reports' do - it 'return the an empty array' do - expect(described_class.terraform_reports).to eq([]) + context 'when there are no terraform reports' do + let!(:artifact) { create(:ci_job_artifact, :archive) } + + it { is_expected.to be_empty } end end end @@ -135,7 +141,7 @@ RSpec.describe Ci::JobArtifact do context 'when given an unrecognized report type' do it 'raises error' do - expect { described_class.file_types_for_report(:blah) }.to raise_error(KeyError, /blah/) + expect { described_class.file_types_for_report(:blah) }.to raise_error(ArgumentError, "Unrecognized report type: blah") end end end @@ -146,8 +152,8 @@ RSpec.describe Ci::JobArtifact do subject { Ci::JobArtifact.associated_file_types_for(file_type) } where(:file_type, :result) do - 'codequality' | %w(codequality) - 'quality' | nil + 'codequality' | %w(codequality) + 'quality' | nil end with_them do @@ -754,4 +760,26 @@ RSpec.describe Ci::JobArtifact do let!(:model) { create(:ci_job_artifact, project: parent) } end end + + describe 'partitioning' do + let(:job) { build(:ci_build, partition_id: 123) } + let(:artifact) { build(:ci_job_artifact, job: job, partition_id: nil) } + + it 'copies the partition_id from job' do + expect { artifact.valid? }.to change(artifact, :partition_id).from(nil).to(123) + end + + context 'when the job is missing' do + let(:artifact) do + build(:ci_job_artifact, + project: build_stubbed(:project), + job: nil, + partition_id: nil) + end + + it 'does not change the partition_id value' do + expect { artifact.valid? }.not_to change(artifact, :partition_id) + end + end + end end |