2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::ImportExport::UploadsSaver do
|
|
|
|
describe 'bundle a project Git repo' do
|
|
|
|
let(:export_path) { "#{Dir.tmpdir}/uploads_saver_spec" }
|
2018-11-08 19:23:39 +05:30
|
|
|
let(:file) { fixture_file_upload('spec/fixtures/banana_sample.gif', 'image/gif') }
|
2018-03-27 19:54:05 +05:30
|
|
|
let(:shared) { project.import_export_shared }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
before do
|
2020-01-01 13:55:28 +05:30
|
|
|
allow_next_instance_of(Gitlab::ImportExport) do |instance|
|
|
|
|
allow(instance).to receive(:storage_path).and_return(export_path)
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
FileUtils.rm_rf(export_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'legacy storage' do
|
2018-03-27 19:54:05 +05:30
|
|
|
let(:project) { create(:project, :legacy_storage) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
subject(:saver) { described_class.new(shared: shared, project: project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
UploadService.new(project, file, FileUploader).execute
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'saves the uploads successfully' do
|
|
|
|
expect(saver.save).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'copies the uploads to the export path' do
|
|
|
|
saver.save
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
uploads = Dir.glob(File.join(shared.export_path, 'uploads/**/*')).map { |file| File.basename(file) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
expect(uploads).to include('banana_sample.gif')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'hashed storage' do
|
2018-03-27 19:54:05 +05:30
|
|
|
let(:project) { create(:project) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
subject(:saver) { described_class.new(shared: shared, project: project) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
UploadService.new(project, file, FileUploader).execute
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'saves the uploads successfully' do
|
|
|
|
expect(saver.save).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'copies the uploads to the export path' do
|
|
|
|
saver.save
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
uploads = Dir.glob(File.join(shared.export_path, 'uploads/**/*')).map { |file| File.basename(file) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
expect(uploads).to include('banana_sample.gif')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|