2020-08-07 02:09:47 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe Ci::PipelineArtifact, type: :model do
|
2021-02-01 16:09:15 -05:00
|
|
|
let(:coverage_report) { create(:ci_pipeline_artifact, :with_coverage_report) }
|
2020-08-07 02:09:47 -04:00
|
|
|
|
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to belong_to(:pipeline) }
|
|
|
|
it { is_expected.to belong_to(:project) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like 'having unique enum values'
|
|
|
|
|
2020-08-24 08:10:17 -04:00
|
|
|
it_behaves_like 'UpdateProjectStatistics' do
|
2020-09-09 08:08:22 -04:00
|
|
|
let_it_be(:pipeline, reload: true) { create(:ci_pipeline) }
|
|
|
|
|
2021-02-01 16:09:15 -05:00
|
|
|
subject { build(:ci_pipeline_artifact, :with_code_coverage_with_multiple_files, pipeline: pipeline) }
|
2020-08-24 08:10:17 -04:00
|
|
|
end
|
|
|
|
|
2020-08-07 02:09:47 -04:00
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to validate_presence_of(:pipeline) }
|
|
|
|
it { is_expected.to validate_presence_of(:project) }
|
|
|
|
it { is_expected.to validate_presence_of(:file_type) }
|
|
|
|
it { is_expected.to validate_presence_of(:file_format) }
|
|
|
|
it { is_expected.to validate_presence_of(:size) }
|
2020-08-12 08:10:25 -04:00
|
|
|
it { is_expected.to validate_presence_of(:file) }
|
2020-08-07 02:09:47 -04:00
|
|
|
|
|
|
|
context 'when attributes are valid' do
|
|
|
|
it 'returns no errors' do
|
|
|
|
expect(coverage_report).to be_valid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when file_store is invalid' do
|
|
|
|
it 'returns errors' do
|
|
|
|
coverage_report.file_store = 0
|
|
|
|
|
|
|
|
expect(coverage_report).to be_invalid
|
|
|
|
expect(coverage_report.errors.full_messages).to eq(["File store is not included in the list"])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when size is over 10 megabytes' do
|
|
|
|
it 'returns errors' do
|
|
|
|
coverage_report.size = 11.megabytes
|
|
|
|
|
|
|
|
expect(coverage_report).to be_invalid
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-08-13 11:10:03 -04:00
|
|
|
|
|
|
|
describe 'file is being stored' do
|
2021-02-01 16:09:15 -05:00
|
|
|
subject { create(:ci_pipeline_artifact, :with_coverage_report) }
|
2020-08-13 11:10:03 -04:00
|
|
|
|
|
|
|
context 'when existing object has local store' do
|
2020-08-19 17:10:32 -04:00
|
|
|
it_behaves_like 'mounted file in local store'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when direct upload is enabled' do
|
|
|
|
before do
|
|
|
|
stub_artifacts_object_storage(Ci::PipelineArtifactUploader, direct_upload: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when file is stored' do
|
|
|
|
it_behaves_like 'mounted file in object store'
|
2020-08-13 11:10:03 -04:00
|
|
|
end
|
|
|
|
end
|
2020-08-21 11:10:03 -04:00
|
|
|
|
|
|
|
context 'when file contains multi-byte characters' do
|
2021-02-01 16:09:15 -05:00
|
|
|
let(:coverage_report_multibyte) { create(:ci_pipeline_artifact, :with_coverage_multibyte_characters) }
|
2020-08-21 11:10:03 -04:00
|
|
|
|
|
|
|
it 'sets the size in bytesize' do
|
2020-08-31 17:10:19 -04:00
|
|
|
expect(coverage_report_multibyte.size).to eq(14)
|
2020-08-21 11:10:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-05 07:09:31 -05:00
|
|
|
describe '.report_exists?' do
|
|
|
|
subject(:pipeline_artifact) { Ci::PipelineArtifact.report_exists?(file_type) }
|
2020-08-21 11:10:03 -04:00
|
|
|
|
2021-01-19 16:10:45 -05:00
|
|
|
context 'when file_type is code_coverage' do
|
|
|
|
let(:file_type) { :code_coverage }
|
|
|
|
|
|
|
|
context 'when pipeline artifact has a coverage report' do
|
2021-02-01 16:09:15 -05:00
|
|
|
let!(:pipeline_artifact) { create(:ci_pipeline_artifact, :with_coverage_report) }
|
2021-01-19 16:10:45 -05:00
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(pipeline_artifact).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pipeline artifact does not have a coverage report' do
|
|
|
|
it 'returns false' do
|
|
|
|
expect(pipeline_artifact).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-03 13:09:25 -05:00
|
|
|
context 'when file_type is code_quality_mr_diff' do
|
|
|
|
let(:file_type) { :code_quality_mr_diff }
|
2021-01-19 16:10:45 -05:00
|
|
|
|
2021-02-03 13:09:25 -05:00
|
|
|
context 'when pipeline artifact has a codequality mr diff report' do
|
|
|
|
let!(:pipeline_artifact) { create(:ci_pipeline_artifact, :with_codequality_mr_diff_report) }
|
2020-08-21 11:10:03 -04:00
|
|
|
|
2021-01-19 16:10:45 -05:00
|
|
|
it 'returns true' do
|
|
|
|
expect(pipeline_artifact).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-03 13:09:25 -05:00
|
|
|
context 'when pipeline artifact does not have a codequality mr diff report' do
|
2021-01-19 16:10:45 -05:00
|
|
|
it 'returns false' do
|
|
|
|
expect(pipeline_artifact).to be_falsey
|
|
|
|
end
|
2020-08-21 11:10:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-19 16:10:45 -05:00
|
|
|
context 'when file_type is nil' do
|
|
|
|
let(:file_type) { nil }
|
|
|
|
|
2020-08-21 11:10:03 -04:00
|
|
|
it 'returns false' do
|
2021-01-19 16:10:45 -05:00
|
|
|
expect(pipeline_artifact).to be_falsey
|
2020-08-21 11:10:03 -04:00
|
|
|
end
|
|
|
|
end
|
2020-08-13 11:10:03 -04:00
|
|
|
end
|
2020-08-25 08:04:30 -04:00
|
|
|
|
2021-01-19 16:10:45 -05:00
|
|
|
describe '.find_by_file_type' do
|
|
|
|
subject(:pipeline_artifact) { Ci::PipelineArtifact.find_by_file_type(file_type) }
|
2020-08-25 08:04:30 -04:00
|
|
|
|
2021-01-19 16:10:45 -05:00
|
|
|
context 'when file_type is code_coverage' do
|
|
|
|
let(:file_type) { :code_coverage }
|
|
|
|
|
|
|
|
context 'when pipeline artifact has a coverage report' do
|
2021-02-01 16:09:15 -05:00
|
|
|
let!(:coverage_report) { create(:ci_pipeline_artifact, :with_coverage_report) }
|
2021-01-19 16:10:45 -05:00
|
|
|
|
|
|
|
it 'returns a pipeline artifact with a coverage report' do
|
|
|
|
expect(pipeline_artifact.file_type).to eq('code_coverage')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pipeline artifact does not have a coverage report' do
|
|
|
|
it 'returns nil' do
|
|
|
|
expect(pipeline_artifact).to be_nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-03 13:09:25 -05:00
|
|
|
context 'when file_type is code_quality_mr_diff' do
|
|
|
|
let(:file_type) { :code_quality_mr_diff }
|
2021-01-19 16:10:45 -05:00
|
|
|
|
|
|
|
context 'when pipeline artifact has a quality report' do
|
2021-02-03 13:09:25 -05:00
|
|
|
let!(:coverage_report) { create(:ci_pipeline_artifact, :with_codequality_mr_diff_report) }
|
2020-08-25 08:04:30 -04:00
|
|
|
|
2021-01-19 16:10:45 -05:00
|
|
|
it 'returns a pipeline artifact with a quality report' do
|
2021-02-03 13:09:25 -05:00
|
|
|
expect(pipeline_artifact.file_type).to eq('code_quality_mr_diff')
|
2021-01-19 16:10:45 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pipeline artifact does not have a quality report' do
|
|
|
|
it 'returns nil' do
|
|
|
|
expect(pipeline_artifact).to be_nil
|
|
|
|
end
|
2020-08-25 08:04:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-19 16:10:45 -05:00
|
|
|
context 'when file_type is nil' do
|
|
|
|
let(:file_type) { nil }
|
|
|
|
|
2020-08-25 08:04:30 -04:00
|
|
|
it 'returns nil' do
|
2021-01-19 16:10:45 -05:00
|
|
|
expect(pipeline_artifact).to be_nil
|
2020-08-25 08:04:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-09-01 17:10:21 -04:00
|
|
|
|
|
|
|
describe '#present' do
|
2021-02-05 07:09:31 -05:00
|
|
|
subject(:presenter) { report.present }
|
2020-09-01 17:10:21 -04:00
|
|
|
|
|
|
|
context 'when file_type is code_coverage' do
|
2021-02-05 07:09:31 -05:00
|
|
|
let(:report) { coverage_report }
|
|
|
|
|
2020-09-01 17:10:21 -04:00
|
|
|
it 'uses code coverage presenter' do
|
2021-02-05 07:09:31 -05:00
|
|
|
expect(presenter).to be_kind_of(Ci::PipelineArtifacts::CodeCoveragePresenter)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when file_type is code_quality_mr_diff' do
|
|
|
|
let(:report) { create(:ci_pipeline_artifact, :with_codequality_mr_diff_report) }
|
|
|
|
|
|
|
|
it 'uses code codequality mr diff presenter' do
|
|
|
|
expect(presenter).to be_kind_of(Ci::PipelineArtifacts::CodeQualityMrDiffPresenter)
|
2020-09-01 17:10:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-08-07 02:09:47 -04:00
|
|
|
end
|