diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2018-08-07 17:35:03 +0300 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2018-08-07 17:35:03 +0300 |
commit | 0d729d5c54b8c1f87f915eb365e8abc189828b68 (patch) | |
tree | f296d6f5833c5eab6b185291570eefad6d6a514f /spec/lib | |
parent | bf699ff49860aa186dc485a91f9b04081b346549 (diff) | |
parent | 6aaeb6dc411d6a92e9dc8d7968aa774c9e8ae044 (diff) |
Merge branch '46535-orphaned-uploads' into 'master'
Rake task for checking orphaned object store uploads
Closes #46535
See merge request gitlab-org/gitlab-ce!20918
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/cleanup/remote_uploads_spec.rb | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/spec/lib/gitlab/cleanup/remote_uploads_spec.rb b/spec/lib/gitlab/cleanup/remote_uploads_spec.rb new file mode 100644 index 00000000000..8d03baeb07b --- /dev/null +++ b/spec/lib/gitlab/cleanup/remote_uploads_spec.rb @@ -0,0 +1,74 @@ +# frozen_string_literal: true +require 'spec_helper' + +describe Gitlab::Cleanup::RemoteUploads do + 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 + 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) + + expect(connection).to receive(:directories).and_return(double(get: directory)) + 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 |