diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/lib/gitlab/import/import_failure_service_spec.rb | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/lib/gitlab/import/import_failure_service_spec.rb')
-rw-r--r-- | spec/lib/gitlab/import/import_failure_service_spec.rb | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/spec/lib/gitlab/import/import_failure_service_spec.rb b/spec/lib/gitlab/import/import_failure_service_spec.rb new file mode 100644 index 00000000000..50b32d634ad --- /dev/null +++ b/spec/lib/gitlab/import/import_failure_service_spec.rb @@ -0,0 +1,136 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Import::ImportFailureService do + let_it_be(:import_type) { 'import_type' } + + let_it_be(:project) do + create( + :project, + :import_started, + import_type: import_type + ) + end + + let(:import_state) { project.import_state } + let(:exception) { StandardError.new('some error') } + + shared_examples 'logs the exception and fails the import' do + it 'when the failure does not abort the import' do + expect(Gitlab::ErrorTracking) + .to receive(:track_exception) + .with( + exception, + project_id: project.id, + import_type: import_type, + source: 'SomeImporter' + ) + + expect(Gitlab::Import::Logger) + .to receive(:error) + .with( + message: 'importer failed', + 'error.message': 'some error', + project_id: project.id, + import_type: import_type, + source: 'SomeImporter' + ) + + described_class.track(**arguments) + + expect(project.import_state.reload.status).to eq('failed') + + expect(project.import_failures).not_to be_empty + expect(project.import_failures.last.exception_class).to eq('StandardError') + expect(project.import_failures.last.exception_message).to eq('some error') + end + end + + shared_examples 'logs the exception and does not fail the import' do + it 'when the failure does not abort the import' do + expect(Gitlab::ErrorTracking) + .to receive(:track_exception) + .with( + exception, + project_id: project.id, + import_type: import_type, + source: 'SomeImporter' + ) + + expect(Gitlab::Import::Logger) + .to receive(:error) + .with( + message: 'importer failed', + 'error.message': 'some error', + project_id: project.id, + import_type: import_type, + source: 'SomeImporter' + ) + + described_class.track(**arguments) + + expect(project.import_state.reload.status).to eq('started') + + expect(project.import_failures).not_to be_empty + expect(project.import_failures.last.exception_class).to eq('StandardError') + expect(project.import_failures.last.exception_message).to eq('some error') + end + end + + context 'when using the project as reference' do + context 'when it fails the import' do + let(:arguments) do + { + project_id: project.id, + exception: exception, + error_source: 'SomeImporter', + fail_import: true + } + end + + it_behaves_like 'logs the exception and fails the import' + end + + context 'when it does not fail the import' do + let(:arguments) do + { + project_id: project.id, + exception: exception, + error_source: 'SomeImporter', + fail_import: false + } + end + + it_behaves_like 'logs the exception and does not fail the import' + end + end + + context 'when using the import_state as reference' do + context 'when it fails the import' do + let(:arguments) do + { + import_state: import_state, + exception: exception, + error_source: 'SomeImporter', + fail_import: true + } + end + + it_behaves_like 'logs the exception and fails the import' + end + + context 'when it does not fail the import' do + let(:arguments) do + { + import_state: import_state, + exception: exception, + error_source: 'SomeImporter', + fail_import: false + } + end + + it_behaves_like 'logs the exception and does not fail the import' + end + end +end |