2019-10-15 05:06:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-05 09:31:33 -05:00
|
|
|
require 'rake_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe 'gitlab:artifacts namespace rake task' do
|
2017-12-05 09:31:33 -05:00
|
|
|
before(:context) do
|
2018-03-22 14:37:47 -04:00
|
|
|
Rake.application.rake_require 'tasks/gitlab/artifacts/migrate'
|
2017-12-05 09:31:33 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:object_storage_enabled) { false }
|
|
|
|
|
|
|
|
before do
|
|
|
|
stub_artifacts_object_storage(enabled: object_storage_enabled)
|
|
|
|
end
|
|
|
|
|
2019-09-20 08:05:52 -04:00
|
|
|
describe 'gitlab:artifacts:migrate' do
|
|
|
|
subject { run_rake_task('gitlab:artifacts:migrate') }
|
2017-12-05 09:31:33 -05:00
|
|
|
|
|
|
|
let!(:artifact) { create(:ci_job_artifact, :archive, file_store: store) }
|
2019-09-20 08:05:52 -04:00
|
|
|
let!(:job_trace) { create(:ci_job_artifact, :trace, file_store: store) }
|
2017-12-05 09:31:33 -05:00
|
|
|
|
|
|
|
context 'when local storage is used' do
|
2018-02-02 08:59:43 -05:00
|
|
|
let(:store) { ObjectStorage::Store::LOCAL }
|
2017-12-05 09:31:33 -05:00
|
|
|
|
|
|
|
context 'and remote storage is defined' do
|
|
|
|
let(:object_storage_enabled) { true }
|
|
|
|
|
|
|
|
it "migrates file to remote storage" do
|
|
|
|
subject
|
|
|
|
|
2018-02-02 08:59:43 -05:00
|
|
|
expect(artifact.reload.file_store).to eq(ObjectStorage::Store::REMOTE)
|
2019-09-20 08:05:52 -04:00
|
|
|
expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::REMOTE)
|
2017-12-05 09:31:33 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and remote storage is not defined' do
|
|
|
|
it "fails to migrate to remote storage" do
|
|
|
|
subject
|
|
|
|
|
2018-02-02 08:59:43 -05:00
|
|
|
expect(artifact.reload.file_store).to eq(ObjectStorage::Store::LOCAL)
|
2019-09-20 08:05:52 -04:00
|
|
|
expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::LOCAL)
|
2017-12-05 09:31:33 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when remote storage is used' do
|
|
|
|
let(:object_storage_enabled) { true }
|
2018-02-02 08:59:43 -05:00
|
|
|
let(:store) { ObjectStorage::Store::REMOTE }
|
2017-12-05 09:31:33 -05:00
|
|
|
|
|
|
|
it "file stays on remote storage" do
|
|
|
|
subject
|
|
|
|
|
2018-02-02 08:59:43 -05:00
|
|
|
expect(artifact.reload.file_store).to eq(ObjectStorage::Store::REMOTE)
|
2019-09-20 08:05:52 -04:00
|
|
|
expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::REMOTE)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'gitlab:artifacts:migrate_to_local' do
|
|
|
|
let(:object_storage_enabled) { true }
|
|
|
|
|
|
|
|
subject { run_rake_task('gitlab:artifacts:migrate_to_local') }
|
|
|
|
|
|
|
|
let!(:artifact) { create(:ci_job_artifact, :archive, file_store: store) }
|
|
|
|
let!(:job_trace) { create(:ci_job_artifact, :trace, file_store: store) }
|
|
|
|
|
|
|
|
context 'when remote storage is used' do
|
|
|
|
let(:store) { ObjectStorage::Store::REMOTE }
|
|
|
|
|
|
|
|
context 'and job has remote file store defined' do
|
|
|
|
it "migrates file to local storage" do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(artifact.reload.file_store).to eq(ObjectStorage::Store::LOCAL)
|
|
|
|
expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::LOCAL)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when local storage is used' do
|
|
|
|
let(:store) { ObjectStorage::Store::LOCAL }
|
|
|
|
|
|
|
|
it 'file stays on local storage' do
|
|
|
|
subject
|
|
|
|
|
|
|
|
expect(artifact.reload.file_store).to eq(ObjectStorage::Store::LOCAL)
|
|
|
|
expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::LOCAL)
|
2017-12-05 09:31:33 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|