Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/groups/import_export/import_service_spec.rb')
-rw-r--r--spec/services/groups/import_export/import_service_spec.rb63
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/services/groups/import_export/import_service_spec.rb b/spec/services/groups/import_export/import_service_spec.rb
index 256e0a1b3c5..1f7eaccbdbd 100644
--- a/spec/services/groups/import_export/import_service_spec.rb
+++ b/spec/services/groups/import_export/import_service_spec.rb
@@ -3,6 +3,47 @@
require 'spec_helper'
describe Groups::ImportExport::ImportService do
+ describe '#async_execute' do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:group) { create(:group) }
+
+ context 'when the job can be successfully scheduled' do
+ subject(:import_service) { described_class.new(group: group, user: user) }
+
+ it 'enqueues an import job' do
+ expect(GroupImportWorker).to receive(:perform_async).with(user.id, group.id)
+
+ import_service.async_execute
+ end
+
+ it 'marks the group import as in progress' do
+ import_service.async_execute
+
+ expect(group.import_state.in_progress?).to eq true
+ end
+
+ it 'returns truthy' do
+ expect(import_service.async_execute).to be_truthy
+ end
+ end
+
+ context 'when the job cannot be scheduled' do
+ subject(:import_service) { described_class.new(group: group, user: user) }
+
+ before do
+ allow(GroupImportWorker).to receive(:perform_async).and_return(nil)
+ end
+
+ it 'returns falsey' do
+ expect(import_service.async_execute).to be_falsey
+ end
+
+ it 'does not mark the group import as created' do
+ expect { import_service.async_execute }.not_to change { group.import_state }
+ end
+ end
+ end
+
context 'with group_import_ndjson feature flag disabled' do
let(:user) { create(:admin) }
let(:group) { create(:group) }
@@ -60,6 +101,7 @@ describe Groups::ImportExport::ImportService do
allow(Gitlab::Import::Logger).to receive(:build).and_return(import_logger)
allow(import_logger).to receive(:error)
allow(import_logger).to receive(:info)
+ allow(FileUtils).to receive(:rm_rf).and_call_original
end
context 'when user has correct permissions' do
@@ -73,6 +115,16 @@ describe Groups::ImportExport::ImportService do
expect(group.import_export_upload.import_file.file).to be_nil
end
+ it 'removes tmp files' do
+ shared = Gitlab::ImportExport::Shared.new(group)
+ allow(Gitlab::ImportExport::Shared).to receive(:new).and_return(shared)
+
+ subject
+
+ expect(FileUtils).to have_received(:rm_rf).with(shared.base_path)
+ expect(Dir.exist?(shared.base_path)).to eq(false)
+ end
+
it 'logs the import success' do
expect(import_logger).to receive(:info).with(
group_id: group.id,
@@ -160,6 +212,7 @@ describe Groups::ImportExport::ImportService do
allow(Gitlab::Import::Logger).to receive(:build).and_return(import_logger)
allow(import_logger).to receive(:error)
allow(import_logger).to receive(:info)
+ allow(FileUtils).to receive(:rm_rf).and_call_original
end
context 'when user has correct permissions' do
@@ -173,6 +226,16 @@ describe Groups::ImportExport::ImportService do
expect(group.import_export_upload.import_file.file).to be_nil
end
+ it 'removes tmp files' do
+ shared = Gitlab::ImportExport::Shared.new(group)
+ allow(Gitlab::ImportExport::Shared).to receive(:new).and_return(shared)
+
+ subject
+
+ expect(FileUtils).to have_received(:rm_rf).with(shared.base_path)
+ expect(Dir.exist?(shared.base_path)).to eq(false)
+ end
+
it 'logs the import success' do
expect(import_logger).to receive(:info).with(
group_id: group.id,