2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::ImportExport::UploadsRestorer do
|
2018-03-17 18:26:18 +05:30
|
|
|
describe 'bundle a project Git repo' do
|
|
|
|
let(:export_path) { "#{Dir.tmpdir}/uploads_saver_spec" }
|
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
|
|
|
FileUtils.mkdir_p(File.join(shared.export_path, 'uploads/random'))
|
2018-11-20 20:47:30 +05:30
|
|
|
FileUtils.touch(File.join(shared.export_path, 'uploads/random', 'dummy.txt'))
|
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(:restorer) { described_class.new(project: project, shared: shared) }
|
|
|
|
|
|
|
|
it 'saves the uploads successfully' do
|
|
|
|
expect(restorer.restore).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'copies the uploads to the project path' do
|
|
|
|
subject.restore
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(project.uploads.map { |u| u.retrieve_uploader.filename }).to include('dummy.txt')
|
2018-03-17 18:26:18 +05:30
|
|
|
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(:restorer) { described_class.new(project: project, shared: shared) }
|
|
|
|
|
|
|
|
it 'saves the uploads successfully' do
|
|
|
|
expect(restorer.restore).to be true
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'copies the uploads to the project path' do
|
|
|
|
subject.restore
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
expect(project.uploads.map { |u| u.retrieve_uploader.filename }).to include('dummy.txt')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|