summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-08-02 11:32:28 +0200
committerJames Lopez <james@jameslopez.es>2016-08-04 12:51:55 +0200
commit6a0bbb5aa58e37a0ad8c3817c4e809143adce1be (patch)
tree7ea74aad1858746674f1fa345cc5f40d32117b78 /spec
parent632113e43cc3296759b11dc20b1b7f2f056278f0 (diff)
downloadgitlab-ce-6a0bbb5aa58e37a0ad8c3817c4e809143adce1be.tar.gz
using shared path for project import uploads and refactored gitlab remove export worker
Diffstat (limited to 'spec')
-rw-r--r--spec/services/import_export_clean_up_service_spec.rb64
1 files changed, 64 insertions, 0 deletions
diff --git a/spec/services/import_export_clean_up_service_spec.rb b/spec/services/import_export_clean_up_service_spec.rb
new file mode 100644
index 00000000000..130b9fc4b82
--- /dev/null
+++ b/spec/services/import_export_clean_up_service_spec.rb
@@ -0,0 +1,64 @@
+require 'spec_helper'
+
+describe ImportExportCleanUpService, services: true do
+ describe '#execute' do
+ let(:service) { described_class.new }
+
+ let(:tmp_import_export_folder) { 'tmp/project_exports' }
+
+ context 'when the import/export directory does not exist' do
+ it 'does not remove any archives' do
+ path = '/invalid/path/'
+ stub_repository_downloads_path(path)
+
+ expect(File).to receive(:directory?).with(path + tmp_import_export_folder).and_return(false).at_least(:once)
+ expect(service).not_to receive(:clean_up_export_files)
+
+ service.execute
+ end
+ end
+
+ context 'when the import/export directory exists' do
+ it 'removes old files' do
+ in_directory_with_files(mtime: 2.days.ago) do |dir, files|
+ service.execute
+
+ files.each { |file| expect(File.exist?(file)).to eq false }
+ expect(File.directory?(dir)).to eq false
+ end
+ end
+
+ it 'does not remove new files' do
+ in_directory_with_files(mtime: 2.hours.ago) do |dir, files|
+ service.execute
+
+ files.each { |file| expect(File.exist?(file)).to eq true }
+ expect(File.directory?(dir)).to eq true
+ end
+ end
+ end
+
+ def in_directory_with_files(mtime:)
+ Dir.mktmpdir do |tmpdir|
+ stub_repository_downloads_path(tmpdir)
+ dir = File.join(tmpdir, tmp_import_export_folder, 'subfolder')
+ FileUtils.mkdir_p(dir)
+
+ files = FileUtils.touch(file_list(dir) + [dir], mtime: mtime)
+
+ yield(dir, files)
+ end
+ end
+
+ def stub_repository_downloads_path(path)
+ new_shared_settings = Settings.shared.merge('path' => path)
+ allow(Settings).to receive(:shared).and_return(new_shared_settings)
+ end
+
+ def file_list(dir)
+ Array.new(5) do |num|
+ File.join(dir, "random-#{num}.tar.gz")
+ end
+ end
+ end
+end