summaryrefslogtreecommitdiff
path: root/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb
diff options
context:
space:
mode:
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.rb137
1 files changed, 53 insertions, 84 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 4c96daea7b3..c1ac5ffebe8 100644
--- a/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb
+++ b/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb
@@ -21,6 +21,12 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do
end.new
end
+ let_it_be(:project) { create(:project, :import_started) }
+
+ let(:importer_class) { double(:importer_class, name: 'klass_name') }
+ let(:importer_instance) { double(:importer_instance) }
+ let(:client) { double(:client) }
+
before do
stub_const('MockRepresantation', Class.new do
include Gitlab::GithubImport::Representation::ToHash
@@ -38,12 +44,7 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do
end)
end
- describe '#import', :clean_gitlab_redis_shared_state do
- let(:importer_class) { double(:importer_class, name: 'klass_name') }
- let(:importer_instance) { double(:importer_instance) }
- let(:project) { double(:project, full_path: 'foo/bar', id: 1) }
- let(:client) { double(:client) }
-
+ describe '#import', :clean_gitlab_redis_cache do
before do
expect(worker)
.to receive(:importer_class)
@@ -60,26 +61,23 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do
expect(importer_instance)
.to receive(:execute)
- expect_next_instance_of(Gitlab::Import::Logger) do |logger|
- expect(logger)
- .to receive(:info)
- .with(
- github_id: 1,
- message: 'starting importer',
- import_source: :github,
- project_id: 1,
- importer: 'klass_name'
- )
- expect(logger)
- .to receive(:info)
- .with(
- github_id: 1,
- message: 'importer finished',
- import_source: :github,
- project_id: 1,
- importer: 'klass_name'
- )
- end
+ expect(Gitlab::GithubImport::Logger)
+ .to receive(:info)
+ .with(
+ github_id: 1,
+ message: 'starting importer',
+ project_id: project.id,
+ importer: 'klass_name'
+ )
+
+ expect(Gitlab::GithubImport::Logger)
+ .to receive(:info)
+ .with(
+ github_id: 1,
+ message: 'importer finished',
+ project_id: project.id,
+ importer: 'klass_name'
+ )
worker.import(project, client, { 'number' => 10, 'github_id' => 1 })
@@ -100,74 +98,45 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter do
.to receive(:execute)
.and_raise(exception)
- expect_next_instance_of(Gitlab::Import::Logger) do |logger|
- expect(logger)
- .to receive(:info)
- .with(
- github_id: 1,
- message: 'starting importer',
- import_source: :github,
- project_id: project.id,
- importer: 'klass_name'
- )
- expect(logger)
- .to receive(:error)
- .with(
- github_id: 1,
- message: 'importer failed',
- import_source: :github,
- project_id: project.id,
- importer: 'klass_name',
- 'error.message': 'some error',
- 'github.data': {
- 'github_id' => 1,
- 'number' => 10
- }
- )
- end
-
- expect(Gitlab::ErrorTracking)
- .to receive(:track_and_raise_exception)
+ expect(Gitlab::GithubImport::Logger)
+ .to receive(:info)
.with(
- exception,
- import_source: :github,
github_id: 1,
- project_id: 1,
+ message: 'starting importer',
+ project_id: project.id,
importer: 'klass_name'
- ).and_call_original
+ )
+
+ expect(Gitlab::Import::ImportFailureService)
+ .to receive(:track)
+ .with(
+ project_id: project.id,
+ exception: exception,
+ error_source: 'klass_name'
+ )
+ .and_call_original
+
+ worker.import(project, client, { 'number' => 10, 'github_id' => 1 })
+
+ expect(project.import_state.reload.status).to eq('started')
- expect { worker.import(project, client, { 'number' => 10, 'github_id' => 1 }) }
- .to raise_error(exception)
+ 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
it 'logs error when representation does not have a github_id' do
expect(importer_class).not_to receive(:new)
- expect_next_instance_of(Gitlab::Import::Logger) do |logger|
- expect(logger)
- .to receive(:error)
- .with(
- github_id: nil,
- message: 'importer failed',
- import_source: :github,
- project_id: project.id,
- importer: 'klass_name',
- 'error.message': 'key not found: :github_id',
- 'github.data': {
- 'number' => 10
- }
- )
- end
-
- expect(Gitlab::ErrorTracking)
- .to receive(:track_and_raise_exception)
+ expect(Gitlab::Import::ImportFailureService)
+ .to receive(:track)
.with(
- an_instance_of(KeyError),
- import_source: :github,
- github_id: nil,
- project_id: 1,
- importer: 'klass_name'
- ).and_call_original
+ project_id: project.id,
+ exception: a_kind_of(KeyError),
+ error_source: 'klass_name',
+ fail_import: true
+ )
+ .and_call_original
expect { worker.import(project, client, { 'number' => 10 }) }
.to raise_error(KeyError, 'key not found: :github_id')