summaryrefslogtreecommitdiff
path: root/spec/services/groups/import_export/import_service_spec.rb
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.rb388
1 files changed, 111 insertions, 277 deletions
diff --git a/spec/services/groups/import_export/import_service_spec.rb b/spec/services/groups/import_export/import_service_spec.rb
index d41acbcc2de..972b12d7ee5 100644
--- a/spec/services/groups/import_export/import_service_spec.rb
+++ b/spec/services/groups/import_export/import_service_spec.rb
@@ -59,32 +59,32 @@ RSpec.describe Groups::ImportExport::ImportService do
end
end
- context 'with group_import_ndjson feature flag disabled' do
+ context 'when importing a ndjson export' do
let(:user) { create(:user) }
let(:group) { create(:group) }
+ let(:import_file) { fixture_file_upload('spec/fixtures/group_export.tar.gz') }
+
let(:import_logger) { instance_double(Gitlab::Import::Logger) }
subject(:service) { described_class.new(group: group, user: user) }
before do
- stub_feature_flags(group_import_ndjson: false)
-
- group.add_owner(user)
-
ImportExportUpload.create!(group: group, import_file: import_file)
allow(Gitlab::Import::Logger).to receive(:build).and_return(import_logger)
allow(import_logger).to receive(:error)
allow(import_logger).to receive(:info)
+ allow(import_logger).to receive(:warn)
+ allow(FileUtils).to receive(:rm_rf).and_call_original
end
- context 'with a json file' do
- let(:import_file) { fixture_file_upload('spec/fixtures/legacy_group_export.tar.gz') }
-
- it 'uses LegacyTreeRestorer to import the file' do
- expect(Gitlab::ImportExport::Group::LegacyTreeRestorer).to receive(:new).and_call_original
+ context 'when user has correct permissions' do
+ before do
+ group.add_owner(user)
+ end
- service.execute
+ it 'imports group structure successfully' do
+ expect(service.execute).to be_truthy
end
it 'tracks the event' do
@@ -95,317 +95,151 @@ RSpec.describe Groups::ImportExport::ImportService do
action: 'create',
label: 'import_group_from_file'
)
- end
- end
-
- context 'with a ndjson file' do
- let(:import_file) { fixture_file_upload('spec/fixtures/group_export.tar.gz') }
- it 'fails to import' do
- expect { service.execute }.to raise_error(Gitlab::ImportExport::Error, 'Incorrect JSON format')
+ expect_snowplow_event(
+ category: 'Groups::ImportExport::ImportService',
+ action: 'create',
+ label: 'import_access_level',
+ user: user,
+ extra: { user_role: 'Owner', import_type: 'import_group_from_file' }
+ )
end
- end
- end
-
- context 'with group_import_ndjson feature flag enabled' do
- before do
- stub_feature_flags(group_import_ndjson: true)
- end
-
- context 'when importing a ndjson export' do
- let(:user) { create(:user) }
- let(:group) { create(:group) }
- let(:import_file) { fixture_file_upload('spec/fixtures/group_export.tar.gz') }
- let(:import_logger) { instance_double(Gitlab::Import::Logger) }
-
- subject(:service) { described_class.new(group: group, user: user) }
-
- before do
- ImportExportUpload.create!(group: group, import_file: import_file)
+ it 'removes import file' do
+ service.execute
- allow(Gitlab::Import::Logger).to receive(:build).and_return(import_logger)
- allow(import_logger).to receive(:error)
- allow(import_logger).to receive(:info)
- allow(import_logger).to receive(:warn)
- allow(FileUtils).to receive(:rm_rf).and_call_original
+ expect(group.import_export_upload.import_file.file).to be_nil
end
- context 'when user has correct permissions' do
- before do
- group.add_owner(user)
- end
+ it 'removes tmp files' do
+ shared = Gitlab::ImportExport::Shared.new(group)
+ allow(Gitlab::ImportExport::Shared).to receive(:new).and_return(shared)
- it 'imports group structure successfully' do
- expect(service.execute).to be_truthy
- end
-
- it 'tracks the event' do
- service.execute
-
- expect_snowplow_event(
- category: 'Groups::ImportExport::ImportService',
- action: 'create',
- label: 'import_group_from_file'
- )
-
- expect_snowplow_event(
- category: 'Groups::ImportExport::ImportService',
- action: 'create',
- label: 'import_access_level',
- user: user,
- extra: { user_role: 'Owner', import_type: 'import_group_from_file' }
- )
- end
-
- it 'removes import file' do
- service.execute
-
- 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)
-
- service.execute
-
- 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,
- group_name: group.name,
- message: 'Group Import/Export: Import succeeded'
- ).once
+ service.execute
- service.execute
- end
+ expect(FileUtils).to have_received(:rm_rf).with(shared.base_path)
+ expect(Dir.exist?(shared.base_path)).to eq(false)
end
- context 'when user does not have correct permissions' do
- it 'logs the error and raises an exception' do
- expect(import_logger).to receive(:error).with(
- group_id: group.id,
- group_name: group.name,
- message: a_string_including('Errors occurred')
- )
+ it 'logs the import success' do
+ expect(import_logger).to receive(:info).with(
+ group_id: group.id,
+ group_name: group.name,
+ message: 'Group Import/Export: Import succeeded'
+ ).once
- expect { service.execute }.to raise_error(Gitlab::ImportExport::Error)
- end
-
- it 'tracks the error' do
- shared = Gitlab::ImportExport::Shared.new(group)
- allow(Gitlab::ImportExport::Shared).to receive(:new).and_return(shared)
-
- expect(shared).to receive(:error) do |param|
- expect(param.message).to include 'does not have required permissions for'
- end
-
- expect { service.execute }.to raise_error(Gitlab::ImportExport::Error)
- end
+ service.execute
end
+ end
- context 'when there are errors with the import file' do
- let(:import_file) { fixture_file_upload('spec/fixtures/symlink_export.tar.gz') }
-
- it 'logs the error and raises an exception' do
- expect(import_logger).to receive(:error).with(
- group_id: group.id,
- group_name: group.name,
- message: a_string_including('Errors occurred')
- ).once
+ context 'when user does not have correct permissions' do
+ it 'logs the error and raises an exception' do
+ expect(import_logger).to receive(:error).with(
+ group_id: group.id,
+ group_name: group.name,
+ message: a_string_including('Errors occurred')
+ )
- expect { service.execute }.to raise_error(Gitlab::ImportExport::Error)
- end
+ expect { service.execute }.to raise_error(Gitlab::ImportExport::Error)
end
- context 'when there are errors with the sub-relations' do
- let(:import_file) { fixture_file_upload('spec/fixtures/group_export_invalid_subrelations.tar.gz') }
+ it 'tracks the error' do
+ shared = Gitlab::ImportExport::Shared.new(group)
+ allow(Gitlab::ImportExport::Shared).to receive(:new).and_return(shared)
- before do
- group.add_owner(user)
+ expect(shared).to receive(:error) do |param|
+ expect(param.message).to include 'does not have required permissions for'
end
- it 'successfully imports the group' do
- expect(service.execute).to be_truthy
- end
-
- it 'logs the import success' do
- allow(Gitlab::Import::Logger).to receive(:build).and_return(import_logger)
+ expect { service.execute }.to raise_error(Gitlab::ImportExport::Error)
+ end
+ end
- expect(import_logger).to receive(:info).with(
- group_id: group.id,
- group_name: group.name,
- message: 'Group Import/Export: Import succeeded'
- )
+ context 'when there are errors with the import file' do
+ let(:import_file) { fixture_file_upload('spec/fixtures/symlink_export.tar.gz') }
- service.execute
+ it 'logs the error and raises an exception' do
+ expect(import_logger).to receive(:error).with(
+ group_id: group.id,
+ group_name: group.name,
+ message: a_string_including('Errors occurred')
+ ).once
- expect_snowplow_event(
- category: 'Groups::ImportExport::ImportService',
- action: 'create',
- label: 'import_access_level',
- user: user,
- extra: { user_role: 'Owner', import_type: 'import_group_from_file' }
- )
- end
+ expect { service.execute }.to raise_error(Gitlab::ImportExport::Error)
end
end
- context 'when importing a json export' do
- let(:user) { create(:user) }
- let(:group) { create(:group) }
- let(:import_file) { fixture_file_upload('spec/fixtures/legacy_group_export.tar.gz') }
-
- let(:import_logger) { instance_double(Gitlab::Import::Logger) }
-
- subject(:service) { described_class.new(group: group, user: user) }
+ context 'when there are errors with the sub-relations' do
+ let(:import_file) { fixture_file_upload('spec/fixtures/group_export_invalid_subrelations.tar.gz') }
before do
- ImportExportUpload.create!(group: group, import_file: import_file)
-
- allow(Gitlab::Import::Logger).to receive(:build).and_return(import_logger)
- allow(import_logger).to receive(:error)
- allow(import_logger).to receive(:warn)
- allow(import_logger).to receive(:info)
- allow(FileUtils).to receive(:rm_rf).and_call_original
+ group.add_owner(user)
end
- context 'when user has correct permissions' do
- before do
- group.add_owner(user)
- end
-
- it 'imports group structure successfully' do
- expect(service.execute).to be_truthy
- end
-
- it 'tracks the event' do
- service.execute
-
- expect_snowplow_event(
- category: 'Groups::ImportExport::ImportService',
- action: 'create',
- label: 'import_group_from_file'
- )
-
- expect_snowplow_event(
- category: 'Groups::ImportExport::ImportService',
- action: 'create',
- label: 'import_access_level',
- user: user,
- extra: { user_role: 'Owner', import_type: 'import_group_from_file' }
- )
- end
-
- it 'removes import file' do
- service.execute
-
- 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)
-
- service.execute
-
- 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,
- group_name: group.name,
- message: 'Group Import/Export: Import succeeded'
- ).once
-
- service.execute
- end
+ it 'successfully imports the group' do
+ expect(service.execute).to be_truthy
end
- context 'when user does not have correct permissions' do
- it 'logs the error and raises an exception' do
- expect(import_logger).to receive(:error).with(
- group_id: group.id,
- group_name: group.name,
- message: a_string_including('Errors occurred')
- )
-
- expect { service.execute }.to raise_error(Gitlab::ImportExport::Error)
- end
+ it 'logs the import success' do
+ allow(Gitlab::Import::Logger).to receive(:build).and_return(import_logger)
- it 'tracks the error' do
- shared = Gitlab::ImportExport::Shared.new(group)
- allow(Gitlab::ImportExport::Shared).to receive(:new).and_return(shared)
+ expect(import_logger).to receive(:info).with(
+ group_id: group.id,
+ group_name: group.name,
+ message: 'Group Import/Export: Import succeeded'
+ )
- expect(shared).to receive(:error) do |param|
- expect(param.message).to include 'does not have required permissions for'
- end
+ service.execute
- expect { service.execute }.to raise_error(Gitlab::ImportExport::Error)
- end
+ expect_snowplow_event(
+ category: 'Groups::ImportExport::ImportService',
+ action: 'create',
+ label: 'import_access_level',
+ user: user,
+ extra: { user_role: 'Owner', import_type: 'import_group_from_file' }
+ )
end
+ end
+ end
- context 'when there are errors with the import file' do
- let(:import_file) { fixture_file_upload('spec/fixtures/legacy_symlink_export.tar.gz') }
-
- it 'logs the error and raises an exception' do
- expect(import_logger).to receive(:error).with(
- group_id: group.id,
- group_name: group.name,
- message: a_string_including('Errors occurred')
- ).once
+ context 'when importing a json export' do
+ let(:user) { create(:user) }
+ let(:group) { create(:group) }
+ let(:import_file) { fixture_file_upload('spec/fixtures/legacy_group_export.tar.gz') }
- expect { service.execute }.to raise_error(Gitlab::ImportExport::Error)
- end
- end
+ let(:import_logger) { instance_double(Gitlab::Import::Logger) }
- context 'when there are errors with the sub-relations' do
- let(:import_file) { fixture_file_upload('spec/fixtures/legacy_group_export_invalid_subrelations.tar.gz') }
+ subject(:service) { described_class.new(group: group, user: user) }
- before do
- group.add_owner(user)
- end
+ before do
+ group.add_owner(user)
+ ImportExportUpload.create!(group: group, import_file: import_file)
- it 'successfully imports the group' do
- expect(service.execute).to be_truthy
- end
+ allow(Gitlab::Import::Logger).to receive(:build).and_return(import_logger)
+ allow(import_logger).to receive(:error)
+ allow(import_logger).to receive(:warn)
+ allow(import_logger).to receive(:info)
+ end
- it 'tracks the event' do
- service.execute
-
- expect_snowplow_event(
- category: 'Groups::ImportExport::ImportService',
- action: 'create',
- label: 'import_group_from_file'
- )
-
- expect_snowplow_event(
- category: 'Groups::ImportExport::ImportService',
- action: 'create',
- label: 'import_access_level',
- user: user,
- extra: { user_role: 'Owner', import_type: 'import_group_from_file' }
- )
- end
+ it 'logs the error and raises an exception' do
+ expect(import_logger).to receive(:error).with(
+ group_id: group.id,
+ group_name: group.name,
+ message: a_string_including('Errors occurred')
+ ).once
- it 'logs the import success' do
- allow(Gitlab::Import::Logger).to receive(:build).and_return(import_logger)
+ expect { service.execute }.to raise_error(Gitlab::ImportExport::Error)
+ end
- expect(import_logger).to receive(:info).with(
- group_id: group.id,
- group_name: group.name,
- message: 'Group Import/Export: Import succeeded'
- )
+ it 'tracks the error' do
+ shared = Gitlab::ImportExport::Shared.new(group)
+ allow(Gitlab::ImportExport::Shared).to receive(:new).and_return(shared)
- service.execute
- end
+ expect(shared).to receive(:error) do |param|
+ expect(param.message).to include 'The import file is incompatible'
end
+
+ expect { service.execute }.to raise_error(Gitlab::ImportExport::Error)
end
end
end