summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2018-07-10 15:29:31 +0200
committerJames Lopez <james@jameslopez.es>2018-07-10 15:29:31 +0200
commit874a4ff16ab883f3b22f8e11474522af120bfa86 (patch)
tree4f64bacb1545567ec8fa35862f8ee6f912764845
parent4c7b120acf503e087d935fce2fe5af3f77d00d1e (diff)
downloadgitlab-ce-874a4ff16ab883f3b22f8e11474522af120bfa86.tar.gz
add more object storage specs
-rw-r--r--lib/gitlab/import_export/uploads_manager.rb6
-rw-r--r--spec/lib/gitlab/import_export/uploads_manager_spec.rb25
2 files changed, 26 insertions, 5 deletions
diff --git a/lib/gitlab/import_export/uploads_manager.rb b/lib/gitlab/import_export/uploads_manager.rb
index b229ab12291..2992c81b731 100644
--- a/lib/gitlab/import_export/uploads_manager.rb
+++ b/lib/gitlab/import_export/uploads_manager.rb
@@ -22,8 +22,6 @@ module Gitlab
return unless Gitlab::ImportExport.object_storage?
return if uploads.empty?
- mkdir_p(uploads_export_path)
-
uploads.each do |upload_model|
next unless upload_model.file
next if upload_model.upload.local? # Already copied
@@ -51,7 +49,9 @@ module Gitlab
end
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|
IO.copy_stream(URI.parse(upload.file.url).open, file)
diff --git a/spec/lib/gitlab/import_export/uploads_manager_spec.rb b/spec/lib/gitlab/import_export/uploads_manager_spec.rb
index dcb065fef24..33c90c3a785 100644
--- a/spec/lib/gitlab/import_export/uploads_manager_spec.rb
+++ b/spec/lib/gitlab/import_export/uploads_manager_spec.rb
@@ -4,6 +4,7 @@ describe Gitlab::ImportExport::UploadsManager do
let(:shared) { project.import_export_shared }
let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" }
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) }
@@ -18,7 +19,7 @@ describe Gitlab::ImportExport::UploadsManager do
describe '#copy' 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
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
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