debian-mirror-gitlab/spec/models/concerns/ci/artifactable_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

129 lines
4.3 KiB
Ruby
Raw Permalink Normal View History

2020-10-24 23:57:45 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Ci::Artifactable do
let(:ci_job_artifact) { build(:ci_job_artifact) }
describe 'artifact properties are included' do
context 'when enum is defined' do
subject { ci_job_artifact }
it { is_expected.to define_enum_for(:file_format).with_values(raw: 1, zip: 2, gzip: 3).with_suffix }
end
context 'when const is defined' do
subject { ci_job_artifact.class }
it { is_expected.to be_const_defined(:FILE_FORMAT_ADAPTERS) }
end
end
2020-11-24 15:15:51 +05:30
describe '#each_blob' do
context 'when file format is gzip' do
context 'when gzip file contains one file' do
let(:artifact) { build(:ci_job_artifact, :junit) }
it 'iterates blob once' do
expect { |b| artifact.each_blob(&b) }.to yield_control.once
end
end
context 'when gzip file contains three files' do
let(:artifact) { build(:ci_job_artifact, :junit_with_three_testsuites) }
it 'iterates blob three times' do
expect { |b| artifact.each_blob(&b) }.to yield_control.exactly(3).times
end
end
2023-07-07 10:43:13 +05:30
context 'when decompressed artifact size validator fails' do
let(:artifact) { build(:ci_job_artifact, :junit) }
before do
allow_next_instance_of(Gitlab::Ci::DecompressedGzipSizeValidator) do |instance|
allow(instance).to receive(:valid?).and_return(false)
end
end
it 'fails on blob' do
expect { |b| artifact.each_blob(&b) }
.to raise_error(::Gitlab::Ci::Artifacts::DecompressedArtifactSizeValidator::FileDecompressionError)
end
end
2020-11-24 15:15:51 +05:30
end
context 'when file format is raw' do
let(:artifact) { build(:ci_job_artifact, :codequality, file_format: :raw) }
it 'iterates blob once' do
expect { |b| artifact.each_blob(&b) }.to yield_control.once
end
end
context 'when there are no adapters for the file format' do
2022-10-11 01:57:18 +05:30
let(:artifact) { build(:ci_job_artifact, :junit, file_format: :zip) }
2020-11-24 15:15:51 +05:30
it 'raises an error' do
expect { |b| artifact.each_blob(&b) }.to raise_error(described_class::NotSupportedAdapterError)
end
end
2022-08-13 15:12:31 +05:30
context 'pushes artifact_size to application context' do
let(:artifact) { create(:ci_job_artifact, :junit) }
it 'logs artifact size', :aggregate_failures do
expect { |b| artifact.each_blob(&b) }.to yield_control.once
expect(Gitlab::ApplicationContext.current).to include("meta.artifact_size" => artifact.size)
end
end
2020-11-24 15:15:51 +05:30
end
2021-03-08 18:12:59 +05:30
context 'ActiveRecord scopes' do
let_it_be(:recently_expired_artifact) { create(:ci_job_artifact, expire_at: 1.day.ago) }
let_it_be(:later_expired_artifact) { create(:ci_job_artifact, expire_at: 2.days.ago) }
let_it_be(:not_expired_artifact) { create(:ci_job_artifact, expire_at: 1.day.from_now) }
describe '.expired_before' do
it 'returns expired artifacts' do
expect(Ci::JobArtifact.expired_before(1.hour.ago))
.to match_array([recently_expired_artifact, later_expired_artifact])
end
end
describe '.expired' do
2022-07-23 23:45:48 +05:30
it 'returns all expired artifacts' do
expect(Ci::JobArtifact.expired).to contain_exactly(recently_expired_artifact, later_expired_artifact)
2021-03-08 18:12:59 +05:30
end
end
2021-04-29 21:17:54 +05:30
describe '.with_files_stored_locally' do
it 'returns artifacts stored locally' do
expect(Ci::JobArtifact.with_files_stored_locally).to contain_exactly(recently_expired_artifact, later_expired_artifact, not_expired_artifact)
end
end
describe '.with_files_stored_remotely' do
let(:remote_artifact) { create(:ci_job_artifact, :remote_store) }
before do
stub_artifacts_object_storage
end
it 'returns artifacts stored remotely' do
expect(Ci::JobArtifact.with_files_stored_remotely).to contain_exactly(remote_artifact)
end
end
describe '.project_id_in' do
context 'when artifacts belongs to projects' do
let(:project_ids) { [recently_expired_artifact.project.id, not_expired_artifact.project.id, non_existing_record_id] }
it 'returns artifacts belonging to projects' do
expect(Ci::JobArtifact.project_id_in(project_ids)).to contain_exactly(recently_expired_artifact, not_expired_artifact)
end
end
end
2021-03-08 18:12:59 +05:30
end
2020-10-24 23:57:45 +05:30
end