diff options
Diffstat (limited to 'spec/services/groups/import_export')
-rw-r--r-- | spec/services/groups/import_export/export_service_spec.rb | 21 | ||||
-rw-r--r-- | spec/services/groups/import_export/import_service_spec.rb | 63 |
2 files changed, 75 insertions, 9 deletions
diff --git a/spec/services/groups/import_export/export_service_spec.rb b/spec/services/groups/import_export/export_service_spec.rb index 7bad68b4e00..ea49b26cc7c 100644 --- a/spec/services/groups/import_export/export_service_spec.rb +++ b/spec/services/groups/import_export/export_service_spec.rb @@ -103,12 +103,14 @@ describe Groups::ImportExport::ExportService do end it 'logs the error' do - expect(shared.logger).to receive(:error).with( - group_id: group.id, - group_name: group.name, - error: expected_message, - message: 'Group Import/Export: Export failed' - ) + expect_next_instance_of(Gitlab::Export::Logger) do |logger| + expect(logger).to receive(:error).with( + group_id: group.id, + group_name: group.name, + errors: expected_message, + message: 'Group Export failed' + ) + end expect { service.execute }.to raise_error(Gitlab::ImportExport::Error) end @@ -132,7 +134,7 @@ describe Groups::ImportExport::ExportService do expect { service.execute }.to raise_error(Gitlab::ImportExport::Error) expect(group.import_export_upload).to be_nil - expect(File.exist?(shared.archive_path)).to eq(false) + expect(Dir.exist?(shared.base_path)).to eq(false) end it 'notifies the user about failed group export' do @@ -157,12 +159,13 @@ describe Groups::ImportExport::ExportService do expect { service.execute }.to raise_error(Gitlab::ImportExport::Error) expect(group.import_export_upload).to be_nil - expect(File.exist?(shared.archive_path)).to eq(false) + expect(Dir.exist?(shared.base_path)).to eq(false) end it 'notifies logger' do allow(service).to receive_message_chain(:tree_exporter, :save).and_return(false) - expect(shared.logger).to receive(:error) + + expect(service.instance_variable_get(:@logger)).to receive(:error) expect { service.execute }.to raise_error(Gitlab::ImportExport::Error) end 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, |