summaryrefslogtreecommitdiff
path: root/spec/services/bulk_imports/uploads_export_service_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/bulk_imports/uploads_export_service_spec.rb')
-rw-r--r--spec/services/bulk_imports/uploads_export_service_spec.rb62
1 files changed, 57 insertions, 5 deletions
diff --git a/spec/services/bulk_imports/uploads_export_service_spec.rb b/spec/services/bulk_imports/uploads_export_service_spec.rb
index 39bcacfdc5e..ad6e005485c 100644
--- a/spec/services/bulk_imports/uploads_export_service_spec.rb
+++ b/spec/services/bulk_imports/uploads_export_service_spec.rb
@@ -3,9 +3,11 @@
require 'spec_helper'
RSpec.describe BulkImports::UploadsExportService do
- let_it_be(:project) { create(:project, avatar: fixture_file_upload('spec/fixtures/rails_sample.png', 'image/png')) }
- let_it_be(:upload) { create(:upload, :with_file, :issuable_upload, uploader: FileUploader, model: project) }
let_it_be(:export_path) { Dir.mktmpdir }
+ let_it_be(:project) { create(:project, avatar: fixture_file_upload('spec/fixtures/rails_sample.png', 'image/png')) }
+
+ let!(:upload) { create(:upload, :with_file, :issuable_upload, uploader: FileUploader, model: project) }
+ let(:exported_filepath) { File.join(export_path, upload.secret, upload.retrieve_uploader.filename) }
subject(:service) { described_class.new(project, export_path) }
@@ -15,10 +17,60 @@ RSpec.describe BulkImports::UploadsExportService do
describe '#execute' do
it 'exports project uploads and avatar' do
- subject.execute
+ service.execute
+
+ expect(File).to exist(File.join(export_path, 'avatar', 'rails_sample.png'))
+ expect(File).to exist(exported_filepath)
+ end
+
+ context 'when upload has underlying file missing' do
+ context 'with an upload missing its file' do
+ it 'does not cause errors' do
+ File.delete(upload.absolute_path)
+
+ expect { service.execute }.not_to raise_error
+
+ expect(File).not_to exist(exported_filepath)
+ end
+ end
+
+ context 'when upload is in object storage' do
+ before do
+ stub_uploads_object_storage(FileUploader)
+ end
+
+ shared_examples 'export with invalid upload' do
+ it 'ignores problematic upload and logs exception' do
+ allow(service).to receive(:download_or_copy_upload).and_raise(exception)
+
+ expect(Gitlab::ErrorTracking)
+ .to receive(:log_exception)
+ .with(
+ instance_of(exception), {
+ portable_id: project.id,
+ portable_class: 'Project',
+ upload_id: upload.id
+ }
+ )
+
+ service.execute
+
+ expect(File).not_to exist(exported_filepath)
+ end
+ end
+
+ context 'when filename is too long' do
+ let(:exception) { Errno::ENAMETOOLONG }
+
+ include_examples 'export with invalid upload'
+ end
+
+ context 'when network exception occurs' do
+ let(:exception) { Net::OpenTimeout }
- expect(File.exist?(File.join(export_path, 'avatar', 'rails_sample.png'))).to eq(true)
- expect(File.exist?(File.join(export_path, upload.secret, upload.retrieve_uploader.filename))).to eq(true)
+ include_examples 'export with invalid upload'
+ end
+ end
end
end
end