add more object storage specs
This commit is contained in:
parent
4c7b120acf
commit
874a4ff16a
2 changed files with 26 additions and 5 deletions
|
@ -22,8 +22,6 @@ module Gitlab
|
||||||
return unless Gitlab::ImportExport.object_storage?
|
return unless Gitlab::ImportExport.object_storage?
|
||||||
return if uploads.empty?
|
return if uploads.empty?
|
||||||
|
|
||||||
mkdir_p(uploads_export_path)
|
|
||||||
|
|
||||||
uploads.each do |upload_model|
|
uploads.each do |upload_model|
|
||||||
next unless upload_model.file
|
next unless upload_model.file
|
||||||
next if upload_model.upload.local? # Already copied
|
next if upload_model.upload.local? # Already copied
|
||||||
|
@ -51,7 +49,9 @@ module Gitlab
|
||||||
end
|
end
|
||||||
|
|
||||||
def download_and_copy(upload)
|
def download_and_copy(upload)
|
||||||
upload_path = File.join(uploads_export_path, upload.filename)
|
mkdir_p(File.join(uploads_export_path, upload.secret))
|
||||||
|
|
||||||
|
upload_path = File.join(uploads_export_path, upload.secret, upload.filename)
|
||||||
|
|
||||||
File.open(upload_path, 'w') do |file|
|
File.open(upload_path, 'w') do |file|
|
||||||
IO.copy_stream(URI.parse(upload.file.url).open, file)
|
IO.copy_stream(URI.parse(upload.file.url).open, file)
|
||||||
|
|
|
@ -4,6 +4,7 @@ describe Gitlab::ImportExport::UploadsManager do
|
||||||
let(:shared) { project.import_export_shared }
|
let(:shared) { project.import_export_shared }
|
||||||
let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" }
|
let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" }
|
||||||
let(:project) { create(:project) }
|
let(:project) { create(:project) }
|
||||||
|
let(:exported_file_path) { "#{shared.export_path}/uploads/#{upload.secret}/#{File.basename(upload.path)}" }
|
||||||
|
|
||||||
subject(:manager) { described_class.new(project: project, shared: shared) }
|
subject(:manager) { described_class.new(project: project, shared: shared) }
|
||||||
|
|
||||||
|
@ -18,7 +19,7 @@ describe Gitlab::ImportExport::UploadsManager do
|
||||||
|
|
||||||
describe '#copy' do
|
describe '#copy' do
|
||||||
context 'when the project has uploads locally stored' do
|
context 'when the project has uploads locally stored' do
|
||||||
let(:upload) { create(:upload) }
|
let(:upload) { create(:upload, :issuable_upload, :with_file, model: project) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
project.uploads << upload
|
project.uploads << upload
|
||||||
|
@ -33,7 +34,27 @@ describe Gitlab::ImportExport::UploadsManager do
|
||||||
it 'copies the file in the correct location when there is an upload' do
|
it 'copies the file in the correct location when there is an upload' do
|
||||||
manager.copy
|
manager.copy
|
||||||
|
|
||||||
expect(File).to exist("#{shared.export_path}/uploads/#{File.basename(upload.path)}")
|
expect(File).to exist(exported_file_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'using object storage' do
|
||||||
|
let!(:upload) { create(:upload, :issuable_upload, :object_storage, model: project) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
stub_feature_flags(import_export_object_storage: true)
|
||||||
|
stub_uploads_object_storage(FileUploader)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'downloads the file to include in an archive' do
|
||||||
|
fake_uri = double
|
||||||
|
|
||||||
|
expect(fake_uri).to receive(:open).and_return(StringIO.new('File content'))
|
||||||
|
expect(URI).to receive(:parse).and_return(fake_uri)
|
||||||
|
|
||||||
|
manager.copy
|
||||||
|
|
||||||
|
expect(File.read(exported_file_path)).to eq('File content')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue