2017-06-01 03:52:19 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-11-23 10:57:27 -05:00
|
|
|
describe LegacyArtifactUploader do
|
2018-02-02 08:59:43 -05:00
|
|
|
let(:store) { described_class::Store::LOCAL }
|
2017-12-05 09:31:33 -05:00
|
|
|
let(:job) { create(:ci_build, artifacts_file_store: store) }
|
2017-11-23 13:41:49 -05:00
|
|
|
let(:uploader) { described_class.new(job, :legacy_artifacts_file) }
|
2018-02-02 08:59:43 -05:00
|
|
|
let(:local_path) { described_class.root }
|
2017-06-01 03:52:19 -04:00
|
|
|
|
2018-02-02 08:59:43 -05:00
|
|
|
subject { uploader }
|
2017-06-01 03:52:19 -04:00
|
|
|
|
2018-02-02 08:59:43 -05:00
|
|
|
# TODO: move to Workhorse::UploadPath
|
|
|
|
describe '.workhorse_upload_path' do
|
|
|
|
subject { described_class.workhorse_upload_path }
|
2017-06-05 01:12:18 -04:00
|
|
|
|
2017-11-23 13:41:49 -05:00
|
|
|
it { is_expected.to start_with(local_path) }
|
2018-02-02 08:59:43 -05:00
|
|
|
it { is_expected.to end_with('tmp/uploads') }
|
2017-06-01 03:52:19 -04:00
|
|
|
end
|
|
|
|
|
2018-02-02 08:59:43 -05:00
|
|
|
it_behaves_like "builds correct paths",
|
|
|
|
store_dir: %r[\d{4}_\d{1,2}/\d+/\d+\z],
|
|
|
|
cache_dir: %r[artifacts/tmp/cache],
|
|
|
|
work_dir: %r[artifacts/tmp/work]
|
2017-06-05 01:12:18 -04:00
|
|
|
|
2018-02-02 08:59:43 -05:00
|
|
|
context 'object store is remote' do
|
|
|
|
before do
|
|
|
|
stub_artifacts_object_storage
|
2017-11-23 13:41:49 -05:00
|
|
|
end
|
2017-06-01 03:52:19 -04:00
|
|
|
|
2018-02-02 08:59:43 -05:00
|
|
|
include_context 'with storage', described_class::Store::REMOTE
|
2017-06-05 01:12:18 -04:00
|
|
|
|
2018-02-02 08:59:43 -05:00
|
|
|
it_behaves_like "builds correct paths",
|
|
|
|
store_dir: %r[\d{4}_\d{1,2}/\d+/\d+\z]
|
2017-06-01 03:52:19 -04:00
|
|
|
end
|
2017-06-12 17:42:11 -04:00
|
|
|
|
|
|
|
describe '#filename' do
|
|
|
|
# we need to use uploader, as this makes to use mounter
|
|
|
|
# which initialises uploader.file object
|
|
|
|
let(:uploader) { job.artifacts_file }
|
|
|
|
|
|
|
|
subject { uploader.filename }
|
|
|
|
|
|
|
|
it { is_expected.to be_nil }
|
|
|
|
end
|
2017-11-23 12:51:20 -05:00
|
|
|
|
|
|
|
context 'file is stored in valid 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')
|
2017-11-23 12:51:20 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
|
|
|
uploader.store!(file)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { uploader.file.path }
|
|
|
|
|
2018-02-02 08:59:43 -05:00
|
|
|
it { is_expected.to start_with("#{uploader.root}") }
|
2017-11-23 12:51:20 -05:00
|
|
|
it { is_expected.to include("/#{job.created_at.utc.strftime('%Y_%m')}/") }
|
2017-11-23 13:53:31 -05:00
|
|
|
it { is_expected.to include("/#{job.project_id}/") }
|
2017-11-23 12:51:20 -05:00
|
|
|
it { is_expected.to end_with("ci_build_artifacts.zip") }
|
|
|
|
end
|
2017-06-01 03:52:19 -04:00
|
|
|
end
|