Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-11-29 12:09:27 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-11-29 12:09:27 +0300
commit518aebfe14a72ba08b5b0a528654805bb2d66cd3 (patch)
tree9e0147148b3c512d69ef941de6d25ae41fcbcfeb /spec/workers/concerns
parent7ee1ce8d781f506180501c5eb07d1dfcfb8b2c6a (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers/concerns')
-rw-r--r--spec/workers/concerns/gitlab/github_import/object_importer_spec.rb72
-rw-r--r--spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb72
2 files changed, 135 insertions, 9 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
diff --git a/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb b/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb
index 03e875bcb87..651ea77a71c 100644
--- a/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb
+++ b/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb
@@ -5,7 +5,13 @@ require 'spec_helper'
RSpec.describe Gitlab::GithubImport::StageMethods do
let(:project) { create(:project) }
let(:worker) do
- Class.new { include(Gitlab::GithubImport::StageMethods) }.new
+ Class.new do
+ def self.name
+ 'DummyStage'
+ end
+
+ include(Gitlab::GithubImport::StageMethods)
+ end.new
end
describe '#perform' do
@@ -30,8 +36,72 @@ RSpec.describe Gitlab::GithubImport::StageMethods do
an_instance_of(Project)
)
+ expect_next_instance_of(Gitlab::Import::Logger) do |logger|
+ expect(logger)
+ .to receive(:info)
+ .with(
+ message: 'starting stage',
+ import_source: :github,
+ project_id: project.id,
+ import_stage: 'DummyStage'
+ )
+ expect(logger)
+ .to receive(:info)
+ .with(
+ message: 'stage finished',
+ import_source: :github,
+ project_id: project.id,
+ import_stage: 'DummyStage'
+ )
+ end
+
worker.perform(project.id)
end
+
+ it 'logs error when import fails' do
+ exception = StandardError.new('some error')
+
+ allow(worker)
+ .to receive(:find_project)
+ .with(project.id)
+ .and_return(project)
+
+ expect(worker)
+ .to receive(:try_import)
+ .and_raise(exception)
+
+ expect_next_instance_of(Gitlab::Import::Logger) do |logger|
+ expect(logger)
+ .to receive(:info)
+ .with(
+ message: 'starting stage',
+ import_source: :github,
+ project_id: project.id,
+ import_stage: 'DummyStage'
+ )
+ expect(logger)
+ .to receive(:error)
+ .with(
+ message: 'stage failed',
+ import_source: :github,
+ project_id: project.id,
+ import_stage: 'DummyStage',
+ 'error.message': 'some error'
+ )
+ end
+
+ expect(Gitlab::ErrorTracking)
+ .to receive(:track_and_raise_exception)
+ .with(
+ exception,
+ import_source: :github,
+ project_id: project.id,
+ import_stage: 'DummyStage'
+ )
+ .and_call_original
+
+ expect { worker.perform(project.id) }.to raise_error(exception)
+ end
end
describe '#try_import' do