debian-mirror-gitlab/spec/lib/gitlab/cleanup/remote_uploads_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
2.3 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Cleanup::RemoteUploads do
2018-11-18 11:00:15 +05:30
context 'when object_storage is enabled' do
let(:connection) { double }
let(:directory) { double }
let!(:uploads) do
[
create(:upload, path: 'dir/file1', store: ObjectStorage::Store::REMOTE),
create(:upload, path: 'dir/file2', store: ObjectStorage::Store::LOCAL)
]
end
2020-10-24 23:57:45 +05:30
2018-11-18 11:00:15 +05:30
let(:remote_files) do
[
double(key: 'dir/file1'),
double(key: 'dir/file2'),
double(key: 'dir/file3'),
double(key: 'lost_and_found/dir/file3')
]
end
before do
stub_uploads_object_storage(FileUploader)
expect(::Fog::Storage).to receive(:new).and_return(connection)
2019-02-15 15:39:39 +05:30
expect(connection).to receive(:directories).and_return(double(new: directory))
2018-11-18 11:00:15 +05:30
expect(directory).to receive(:files).and_return(remote_files)
end
context 'when dry_run is set to false' do
subject { described_class.new.run!(dry_run: false) }
it 'moves files that are not in uploads table' do
expect(remote_files[0]).not_to receive(:copy)
expect(remote_files[0]).not_to receive(:destroy)
expect(remote_files[1]).to receive(:copy)
expect(remote_files[1]).to receive(:destroy)
expect(remote_files[2]).to receive(:copy)
expect(remote_files[2]).to receive(:destroy)
expect(remote_files[3]).not_to receive(:copy)
expect(remote_files[3]).not_to receive(:destroy)
subject
end
end
context 'when dry_run is set to true' do
subject { described_class.new.run!(dry_run: true) }
it 'does not move filese' do
expect(remote_files[0]).not_to receive(:copy)
expect(remote_files[0]).not_to receive(:destroy)
expect(remote_files[1]).not_to receive(:copy)
expect(remote_files[1]).not_to receive(:destroy)
expect(remote_files[2]).not_to receive(:copy)
expect(remote_files[2]).not_to receive(:destroy)
expect(remote_files[3]).not_to receive(:copy)
expect(remote_files[3]).not_to receive(:destroy)
subject
end
end
end
context 'when object_storage is not enabled' do
it 'does not connect to any storage' do
expect(::Fog::Storage).not_to receive(:new)
subject
end
end
end