gitlab-org--gitlab-foss/spec/uploaders/job_artifact_uploader_spec.rb

59 lines
1.6 KiB
Ruby
Raw Normal View History

require 'spec_helper'
describe JobArtifactUploader do
2017-11-23 13:41:49 -05:00
let(:job_artifact) { create(:ci_job_artifact) }
let(:uploader) { described_class.new(job_artifact, :file) }
2018-01-29 12:57:34 -05:00
subject { uploader }
2018-01-29 12:57:34 -05:00
it_behaves_like "builds correct paths",
store_dir: %r[\h{2}/\h{2}/\h{64}/\d{4}_\d{1,2}_\d{1,2}/\d+/\d+\z],
cache_dir: %r[artifacts/tmp/cache],
work_dir: %r[artifacts/tmp/work]
2018-01-29 11:56:12 -05:00
describe '#open' do
subject { uploader.open }
context 'when trace is stored in File storage' do
context 'when file exists' do
let(:file) do
fixture_file_upload(
Rails.root.join('spec/fixtures/trace/sample_trace'), 'text/plain')
end
before do
uploader.store!(file)
end
it 'returns io stream' do
is_expected.to be_a(IO)
end
end
context 'when file does not exist' do
it 'returns nil' do
is_expected.to be_nil
end
end
end
end
2017-11-23 13:41:49 -05:00
context 'file is stored in valid local_path' do
let(:file) do
2017-11-23 13:53:31 -05:00
fixture_file_upload(
Rails.root.join('spec/fixtures/ci_build_artifacts.zip'), 'application/zip')
end
before do
uploader.store!(file)
end
subject { uploader.file.path }
2018-01-29 12:57:34 -05:00
it { is_expected.to start_with("#{uploader.root}/#{uploader.class.base_dir}") }
it { is_expected.to include("/#{job_artifact.created_at.utc.strftime('%Y_%m_%d')}/") }
it { is_expected.to include("/#{job_artifact.job_id}/#{job_artifact.id}/") }
it { is_expected.to end_with("ci_build_artifacts.zip") }
end
end