diff options
Diffstat (limited to 'spec/workers/concerns/gitlab/github_import/object_importer_spec.rb')
-rw-r--r-- | spec/workers/concerns/gitlab/github_import/object_importer_spec.rb | 72 |
1 files changed, 64 insertions, 8 deletions
diff --git a/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb b/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb index d0cbc6b35e2..75f2c7922de 100644 --- a/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb +++ b/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb @@ -22,20 +22,21 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do end describe '#import' do - it 'imports the object' do - representation_class = double(:representation_class) - importer_class = double(:importer_class) - importer_instance = double(:importer_instance) - representation = double(:representation) - project = double(:project, full_path: 'foo/bar') - client = double(:client) - + let(:representation_class) { double(:representation_class) } + let(:importer_class) { double(:importer_class, name: 'klass_name') } + let(:importer_instance) { double(:importer_instance) } + let(:representation) { double(:representation) } + let(:project) { double(:project, full_path: 'foo/bar', id: 1) } + let(:client) { double(:client) } + + before do expect(worker) .to receive(:representation_class) .and_return(representation_class) expect(worker) .to receive(:importer_class) + .at_least(:once) .and_return(importer_class) expect(representation_class) @@ -47,7 +48,9 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do .to receive(:new) .with(representation, project, client) .and_return(importer_instance) + end + it 'imports the object' do expect(importer_instance) .to receive(:execute) @@ -55,8 +58,61 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do .to receive(:increment) .and_call_original + expect_next_instance_of(Gitlab::Import::Logger) do |logger| + expect(logger) + .to receive(:info) + .with( + message: 'starting importer', + import_source: :github, + project_id: 1, + importer: 'klass_name' + ) + expect(logger) + .to receive(:info) + .with( + message: 'importer finished', + import_source: :github, + project_id: 1, + importer: 'klass_name' + ) + end + worker.import(project, client, { 'number' => 10 }) end + + it 'logs error when the import fails' do + exception = StandardError.new('some error') + expect(importer_instance) + .to receive(:execute) + .and_raise(exception) + + expect_next_instance_of(Gitlab::Import::Logger) do |logger| + expect(logger) + .to receive(:info) + .with( + message: 'starting importer', + import_source: :github, + project_id: project.id, + importer: 'klass_name' + ) + expect(logger) + .to receive(:error) + .with( + message: 'importer failed', + import_source: :github, + project_id: project.id, + importer: 'klass_name', + 'error.message': 'some error' + ) + end + + expect(Gitlab::ErrorTracking) + .to receive(:track_and_raise_exception) + .with(exception, import_source: :github, project_id: 1, importer: 'klass_name') + .and_call_original + + expect { worker.import(project, client, { 'number' => 10 }) }.to raise_error(exception) + end end describe '#counter' do |