diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-05 18:08:19 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-05 18:08:19 +0000 |
commit | a8de96bff51846e160b76506dc0ca0fe6f767f64 (patch) | |
tree | 1036f1ca75aba492eaaa3439c84a3109b4684896 /spec/services/groups | |
parent | afe2b984524ae4b0c8a0636db7ec5b2c452f0734 (diff) | |
download | gitlab-ce-a8de96bff51846e160b76506dc0ca0fe6f767f64.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/groups')
-rw-r--r-- | spec/services/groups/import_export/export_service_spec.rb | 25 | ||||
-rw-r--r-- | spec/services/groups/import_export/import_service_spec.rb | 75 |
2 files changed, 95 insertions, 5 deletions
diff --git a/spec/services/groups/import_export/export_service_spec.rb b/spec/services/groups/import_export/export_service_spec.rb index 5eebf08892a..0d7fa98e16b 100644 --- a/spec/services/groups/import_export/export_service_spec.rb +++ b/spec/services/groups/import_export/export_service_spec.rb @@ -38,12 +38,31 @@ describe Groups::ImportExport::ExportService do let!(:another_user) { create(:user) } let(:service) { described_class.new(group: group, user: another_user, params: { shared: shared }) } + let(:expected_message) do + "User with ID: %s does not have required permissions for Group: %s with ID: %s" % + [another_user.id, group.name, group.id] + end + it 'fails' do - expected_message = - "User with ID: %s does not have permission to Group %s with ID: %s." % - [another_user.id, group.name, group.id] expect { service.execute }.to raise_error(Gitlab::ImportExport::Error).with_message(expected_message) 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 { service.execute }.to raise_error(Gitlab::ImportExport::Error) + end + + it 'tracks the error' do + expect(shared).to receive(:error) { |param| expect(param.message).to eq expected_message } + + expect { service.execute }.to raise_error(Gitlab::ImportExport::Error) + end end context 'when export fails' do diff --git a/spec/services/groups/import_export/import_service_spec.rb b/spec/services/groups/import_export/import_service_spec.rb index bac266d08da..49c786ef67f 100644 --- a/spec/services/groups/import_export/import_service_spec.rb +++ b/spec/services/groups/import_export/import_service_spec.rb @@ -9,6 +9,8 @@ describe Groups::ImportExport::ImportService do let(:service) { described_class.new(group: group, user: user) } let(:import_file) { fixture_file_upload('spec/fixtures/group_export.tar.gz') } + let(:import_logger) { instance_double(Gitlab::Import::Logger) } + subject { service.execute } before do @@ -25,13 +27,82 @@ describe Groups::ImportExport::ImportService do expect(group.import_export_upload.import_file.file).to be_nil end + + it 'logs the import success' do + allow(Gitlab::Import::Logger).to receive(:build).and_return(import_logger) + + expect(import_logger).to receive(:info).with( + group_id: group.id, + group_name: group.name, + message: 'Group Import/Export: Import succeeded' + ) + + subject + end end context 'when user does not have correct permissions' do let(:user) { create(:user) } - it 'raises exception' do - expect { subject }.to raise_error(StandardError) + it 'logs the error and raises an exception' do + allow(Gitlab::Import::Logger).to receive(:build).and_return(import_logger) + + expect(import_logger).to receive(:error).with( + group_id: group.id, + group_name: group.name, + message: a_string_including('Errors occurred') + ) + + expect { subject }.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 { subject }.to raise_error(Gitlab::ImportExport::Error) + end + end + + context 'when there are errors with the import file' do + let(:import_file) { fixture_file_upload('spec/fixtures/symlink_export.tar.gz') } + + before do + allow(Gitlab::Import::Logger).to receive(:build).and_return(import_logger) + 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') + ) + + expect { subject }.to raise_error(Gitlab::ImportExport::Error) + end + 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 'successfully imports the group' do + expect(subject).to be_truthy + end + + it 'logs the import success' do + allow(Gitlab::Import::Logger).to receive(:build).and_return(import_logger) + + expect(import_logger).to receive(:info).with( + group_id: group.id, + group_name: group.name, + message: 'Group Import/Export: Import succeeded' + ) + + subject end end end |