2017-11-23 17:04:35 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::ImportExport::UploadsRestorer do
|
|
|
|
describe 'bundle a project Git repo' do
|
|
|
|
let(:export_path) { "#{Dir.tmpdir}/uploads_saver_spec" }
|
|
|
|
let(:shared) { Gitlab::ImportExport::Shared.new(relative_path: project.full_path) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
|
|
|
|
FileUtils.mkdir_p(File.join(shared.export_path, 'uploads/random'))
|
|
|
|
FileUtils.touch(File.join(shared.export_path, 'uploads/random', "dummy.txt"))
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
FileUtils.rm_rf(export_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'legacy storage' do
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
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
|
2018-01-29 17:57:34 +00:00
|
|
|
subject.restore
|
2017-11-23 17:04:35 +00:00
|
|
|
|
2018-01-29 17:57:34 +00:00
|
|
|
uploads = Dir.glob(File.join(subject.uploads_path, '**/*')).map { |file| File.basename(file) }
|
2017-11-23 17:04:35 +00:00
|
|
|
|
|
|
|
expect(uploads).to include('dummy.txt')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'hashed storage' do
|
|
|
|
let(:project) { create(:project, :hashed) }
|
|
|
|
|
|
|
|
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
|
2018-01-29 17:57:34 +00:00
|
|
|
subject.restore
|
2017-11-23 17:04:35 +00:00
|
|
|
|
2018-01-29 17:57:34 +00:00
|
|
|
uploads = Dir.glob(File.join(subject.uploads_path, '**/*')).map { |file| File.basename(file) }
|
2017-11-23 17:04:35 +00:00
|
|
|
|
|
|
|
expect(uploads).to include('dummy.txt')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|