Commit 04625437 authored by Shinya Maeda's avatar Shinya Maeda

Add tests

parent c00a4cb6
...@@ -38,6 +38,40 @@ shared_examples "migrates" do |to_store:, from_store: nil| ...@@ -38,6 +38,40 @@ shared_examples "migrates" do |to_store:, from_store: nil|
expect(File.exist?(original_file)).to be_falsey expect(File.exist?(original_file)).to be_falsey
end end
it 'can access to the original file during migration' do
original_file = subject.file.path
allow(subject).to receive(:delete_migrated_file) { }
expect { migrate(to) }.not_to change { File.exist?(original_file) }
end
context 'when migrate! is not oqqupied by another process' do
it 'executes migrate!' do
expect(subject).to receive(:object_store=)
migrate(to)
end
end
context 'when migrate! is oqqupied by another process' do
let(:exclusive_lease_key) { "object_storage_migrate:#{subject.store_path}" }
before do
@uuid = Gitlab::ExclusiveLease.new(exclusive_lease_key, timeout: 1.hour.to_i).try_obtain
end
it 'does not execute migrate!' do
expect(subject).not_to receive(:object_store=)
migrate(to)
end
after do
Gitlab::ExclusiveLease.cancel(exclusive_lease_key, @uuid)
end
end
context 'migration is unsuccessful' do context 'migration is unsuccessful' do
shared_examples "handles gracefully" do |error:| shared_examples "handles gracefully" do |error:|
it 'does not update the object_store' do it 'does not update the object_store' do
......
...@@ -67,4 +67,14 @@ describe JobArtifactUploader do ...@@ -67,4 +67,14 @@ describe JobArtifactUploader do
it { is_expected.to include("/#{job_artifact.job_id}/#{job_artifact.id}/") } it { is_expected.to include("/#{job_artifact.job_id}/#{job_artifact.id}/") }
it { is_expected.to end_with("ci_build_artifacts.zip") } it { is_expected.to end_with("ci_build_artifacts.zip") }
end end
describe "#migrate!" do
before do
uploader.store!(fixture_file_upload(Rails.root.join('spec/fixtures/trace/sample_trace')))
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
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment