summaryrefslogtreecommitdiff
path: root/spec/services/groups
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/groups')
-rw-r--r--spec/services/groups/import_export/export_service_spec.rb10
-rw-r--r--spec/services/groups/import_export/import_service_spec.rb388
-rw-r--r--spec/services/groups/transfer_service_spec.rb37
-rw-r--r--spec/services/groups/update_shared_runners_service_spec.rb28
4 files changed, 172 insertions, 291 deletions
diff --git a/spec/services/groups/import_export/export_service_spec.rb b/spec/services/groups/import_export/export_service_spec.rb
index d6ce40f413b..ec42a728409 100644
--- a/spec/services/groups/import_export/export_service_spec.rb
+++ b/spec/services/groups/import_export/export_service_spec.rb
@@ -56,21 +56,11 @@ RSpec.describe Groups::ImportExport::ExportService do
end
it 'saves the models using ndjson tree saver' do
- stub_feature_flags(group_export_ndjson: true)
-
expect(Gitlab::ImportExport::Group::TreeSaver).to receive(:new).and_call_original
service.execute
end
- it 'saves the models using legacy tree saver' do
- stub_feature_flags(group_export_ndjson: false)
-
- expect(Gitlab::ImportExport::Group::LegacyTreeSaver).to receive(:new).and_call_original
-
- service.execute
- end
-
it 'compresses and removes tmp files' do
expect(group.import_export_upload).to be_nil
expect(Gitlab::ImportExport::Saver).to receive(:new).and_call_original
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
diff --git a/spec/services/groups/transfer_service_spec.rb b/spec/services/groups/transfer_service_spec.rb
index 3cf2c875341..10399bed655 100644
--- a/spec/services/groups/transfer_service_spec.rb
+++ b/spec/services/groups/transfer_service_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe Groups::TransferService, :sidekiq_inline do
+RSpec.describe Groups::TransferService, :sidekiq_inline, feature_category: :subgroups do
shared_examples 'project namespace path is in sync with project path' do
it 'keeps project and project namespace attributes in sync' do
projects_with_project_namespace.each do |project|
@@ -364,7 +364,7 @@ RSpec.describe Groups::TransferService, :sidekiq_inline do
let(:new_parent_group) { create(:group, shared_runners_enabled: false, allow_descendants_override_disabled_shared_runners: true) }
it 'calls update service' do
- expect(Groups::UpdateSharedRunnersService).to receive(:new).with(group, user, { shared_runners_setting: Namespace::SR_DISABLED_WITH_OVERRIDE }).and_call_original
+ expect(Groups::UpdateSharedRunnersService).to receive(:new).with(group, user, { shared_runners_setting: Namespace::SR_DISABLED_AND_OVERRIDABLE }).and_call_original
transfer_service.execute(new_parent_group)
end
@@ -1005,5 +1005,38 @@ RSpec.describe Groups::TransferService, :sidekiq_inline do
end
end
end
+
+ context 'with namespace_commit_emails concerns' do
+ let_it_be(:group, reload: true) { create(:group) }
+ let_it_be(:target) { create(:group) }
+
+ before do
+ group.add_owner(user)
+ target.add_owner(user)
+ end
+
+ context 'when origin is a root group' do
+ before do
+ create_list(:namespace_commit_email, 2, namespace: group)
+ end
+
+ it 'deletes all namespace_commit_emails' do
+ expect { transfer_service.execute(target) }
+ .to change { group.namespace_commit_emails.count }.by(-2)
+ end
+
+ it_behaves_like 'publishes a GroupTransferedEvent'
+ end
+
+ context 'when origin is not a root group' do
+ let(:group) { create(:group, parent: create(:group)) }
+
+ it 'does not attempt to delete namespace_commit_emails' do
+ expect(Users::NamespaceCommitEmail).not_to receive(:delete_for_namespace)
+
+ transfer_service.execute(target)
+ end
+ end
+ end
end
end
diff --git a/spec/services/groups/update_shared_runners_service_spec.rb b/spec/services/groups/update_shared_runners_service_spec.rb
index 98eccedeace..a29f73a71c2 100644
--- a/spec/services/groups/update_shared_runners_service_spec.rb
+++ b/spec/services/groups/update_shared_runners_service_spec.rb
@@ -114,13 +114,13 @@ RSpec.describe Groups::UpdateSharedRunnersService do
end
context 'allow descendants to override' do
- let(:params) { { shared_runners_setting: Namespace::SR_DISABLED_WITH_OVERRIDE } }
+ let(:params) { { shared_runners_setting: Namespace::SR_DISABLED_AND_OVERRIDABLE } }
context 'top level group' do
let_it_be(:group) { create(:group, :shared_runners_disabled) }
it 'receives correct method and succeeds' do
- expect(group).to receive(:update_shared_runners_setting!).with(Namespace::SR_DISABLED_WITH_OVERRIDE)
+ expect(group).to receive(:update_shared_runners_setting!).with(Namespace::SR_DISABLED_AND_OVERRIDABLE)
expect(subject[:status]).to eq(:success)
end
@@ -135,6 +135,30 @@ RSpec.describe Groups::UpdateSharedRunnersService do
expect(subject[:message]).to eq('Validation failed: Allow descendants override disabled shared runners cannot be enabled because parent group does not allow it')
end
end
+
+ context 'when using DISABLED_WITH_OVERRIDE (deprecated)' do
+ let(:params) { { shared_runners_setting: Namespace::SR_DISABLED_WITH_OVERRIDE } }
+
+ context 'top level group' do
+ let_it_be(:group) { create(:group, :shared_runners_disabled) }
+
+ it 'receives correct method and succeeds' do
+ expect(group).to receive(:update_shared_runners_setting!).with(Namespace::SR_DISABLED_WITH_OVERRIDE)
+
+ expect(subject[:status]).to eq(:success)
+ end
+ end
+
+ context 'when parent does not allow' do
+ let_it_be(:parent) { create(:group, :shared_runners_disabled, allow_descendants_override_disabled_shared_runners: false) }
+ let_it_be(:group) { create(:group, :shared_runners_disabled, allow_descendants_override_disabled_shared_runners: false, parent: parent) }
+
+ it 'results error' do
+ expect(subject[:status]).to eq(:error)
+ expect(subject[:message]).to eq('Validation failed: Allow descendants override disabled shared runners cannot be enabled because parent group does not allow it')
+ end
+ end
+ end
end
end
end