2017-09-21 08:34:12 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe JobArtifactUploader do
|
2018-02-02 13:59:43 +00:00
|
|
|
let(:store) { described_class::Store::LOCAL }
|
2017-12-05 14:31:33 +00:00
|
|
|
let(:job_artifact) { create(:ci_job_artifact, file_store: store) }
|
2017-09-21 08:34:12 +00:00
|
|
|
let(:uploader) { described_class.new(job_artifact, :file) }
|
|
|
|
|
2018-02-02 13:59:43 +00:00
|
|
|
subject { uploader }
|
2017-09-21 08:34:12 +00:00
|
|
|
|
2018-02-02 13:59:43 +00: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]
|
2017-11-23 18:41:49 +00:00
|
|
|
|
2018-02-02 13:59:43 +00:00
|
|
|
context "object store is REMOTE" do
|
|
|
|
before do
|
|
|
|
stub_artifacts_object_storage
|
2017-11-23 18:41:49 +00:00
|
|
|
end
|
2017-11-23 17:51:20 +00:00
|
|
|
|
2018-02-02 13:59:43 +00:00
|
|
|
include_context 'with storage', described_class::Store::REMOTE
|
2017-11-23 17:51:20 +00:00
|
|
|
|
2018-02-02 13:59:43 +00: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]
|
2017-11-23 17:51:20 +00:00
|
|
|
end
|
|
|
|
|
2018-02-06 14:18:32 +00:00
|
|
|
describe '#open' do
|
|
|
|
subject { uploader.open }
|
|
|
|
|
|
|
|
context 'when trace is stored in File storage' do
|
|
|
|
context 'when file exists' do
|
|
|
|
let(:file) do
|
2018-06-06 21:26:00 +00:00
|
|
|
fixture_file_upload('spec/fixtures/trace/sample_trace', 'text/plain')
|
2018-02-06 14:18:32 +00:00
|
|
|
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
|
2018-03-02 18:21:03 +00:00
|
|
|
|
|
|
|
context 'when trace is stored in Object storage' do
|
|
|
|
before do
|
|
|
|
allow(uploader).to receive(:file_storage?) { false }
|
|
|
|
allow(uploader).to receive(:url) { 'http://object_storage.com/trace' }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns http io stream' do
|
|
|
|
is_expected.to be_a(Gitlab::Ci::Trace::HttpIO)
|
|
|
|
end
|
|
|
|
end
|
2018-02-06 14:18:32 +00:00
|
|
|
end
|
|
|
|
|
2017-11-23 18:41:49 +00:00
|
|
|
context 'file is stored in valid local_path' do
|
2017-11-23 17:51:20 +00:00
|
|
|
let(:file) do
|
2018-06-06 21:26:00 +00:00
|
|
|
fixture_file_upload('spec/fixtures/ci_build_artifacts.zip', 'application/zip')
|
2017-11-23 17:51:20 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
uploader.store!(file)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { uploader.file.path }
|
|
|
|
|
2018-02-02 13:59:43 +00:00
|
|
|
it { is_expected.to start_with("#{uploader.root}/#{uploader.class.base_dir}") }
|
2017-11-23 17:51:20 +00:00
|
|
|
it { is_expected.to include("/#{job_artifact.created_at.utc.strftime('%Y_%m_%d')}/") }
|
2018-01-17 11:30:25 +00:00
|
|
|
it { is_expected.to include("/#{job_artifact.job_id}/#{job_artifact.id}/") }
|
2017-11-23 17:51:20 +00:00
|
|
|
it { is_expected.to end_with("ci_build_artifacts.zip") }
|
|
|
|
end
|
2018-02-27 13:09:33 +00:00
|
|
|
|
|
|
|
describe "#migrate!" do
|
|
|
|
before do
|
2018-06-06 21:26:00 +00:00
|
|
|
uploader.store!(fixture_file_upload('spec/fixtures/trace/sample_trace'))
|
2018-02-27 13:09:33 +00:00
|
|
|
stub_artifacts_object_storage
|
|
|
|
end
|
|
|
|
|
|
|
|
it_behaves_like "migrates", to_store: described_class::Store::REMOTE
|
|
|
|
it_behaves_like "migrates", from_store: described_class::Store::REMOTE, to_store: described_class::Store::LOCAL
|
|
|
|
end
|
2017-09-21 08:34:12 +00:00
|
|
|
end
|