diff options
Diffstat (limited to 'spec/services/groups/import_export/import_service_spec.rb')
-rw-r--r-- | spec/services/groups/import_export/import_service_spec.rb | 75 |
1 files changed, 73 insertions, 2 deletions
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 |