diff options
Diffstat (limited to 'spec/lib/bulk_imports')
4 files changed, 59 insertions, 17 deletions
diff --git a/spec/lib/bulk_imports/common/pipelines/entity_finisher_spec.rb b/spec/lib/bulk_imports/common/pipelines/entity_finisher_spec.rb index b96ea20c676..e1ad9c75dcb 100644 --- a/spec/lib/bulk_imports/common/pipelines/entity_finisher_spec.rb +++ b/spec/lib/bulk_imports/common/pipelines/entity_finisher_spec.rb @@ -10,16 +10,13 @@ RSpec.describe BulkImports::Common::Pipelines::EntityFinisher, feature_category: subject = described_class.new(context) expect_next_instance_of(BulkImports::Logger) do |logger| + expect(logger).to receive(:with_entity).with(entity).and_call_original + expect(logger) .to receive(:info) .with( - bulk_import_id: entity.bulk_import_id, - bulk_import_entity_id: entity.id, - bulk_import_entity_type: entity.source_type, - source_full_path: entity.source_full_path, pipeline_class: described_class.name, - message: 'Entity finished', - source_version: entity.bulk_import.source_version_info.to_s + message: 'Entity finished' ) end diff --git a/spec/lib/bulk_imports/common/pipelines/lfs_objects_pipeline_spec.rb b/spec/lib/bulk_imports/common/pipelines/lfs_objects_pipeline_spec.rb index 5ba9bd08009..5662c4d7bdc 100644 --- a/spec/lib/bulk_imports/common/pipelines/lfs_objects_pipeline_spec.rb +++ b/spec/lib/bulk_imports/common/pipelines/lfs_objects_pipeline_spec.rb @@ -192,7 +192,7 @@ RSpec.describe BulkImports::Common::Pipelines::LfsObjectsPipeline, feature_categ allow(object).to receive(:persisted?).and_return(false) end - expect_next_instance_of(Gitlab::Import::Logger) do |logger| + expect_next_instance_of(BulkImports::Logger) do |logger| expect(logger) .to receive(:warn) .with(project_id: portable.id, diff --git a/spec/lib/bulk_imports/logger_spec.rb b/spec/lib/bulk_imports/logger_spec.rb new file mode 100644 index 00000000000..889e5573c66 --- /dev/null +++ b/spec/lib/bulk_imports/logger_spec.rb @@ -0,0 +1,49 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BulkImports::Logger, feature_category: :importers do + describe '#with_entity' do + subject(:logger) { described_class.new('/dev/null').with_entity(entity) } + + let(:entity) { build(:bulk_import_entity) } + + it 'records the entity information' do + output = logger.format_message('INFO', Time.zone.now, 'test', 'Hello world') + data = Gitlab::Json.parse(output) + + expect(data).to include( + 'bulk_import_id' => entity.bulk_import_id, + 'bulk_import_entity_id' => entity.id, + 'bulk_import_entity_type' => entity.source_type, + 'source_full_path' => entity.source_full_path, + 'source_version' => entity.bulk_import.source_version_info.to_s + ) + end + end + + describe '#with_tracker' do + subject(:logger) { described_class.new('/dev/null').with_tracker(tracker) } + + let_it_be(:tracker) { build(:bulk_import_tracker) } + + it 'records the tracker information' do + output = logger.format_message('INFO', Time.zone.now, 'test', 'Hello world') + data = Gitlab::Json.parse(output) + + expect(data).to include( + 'tracker_id' => tracker.id, + 'pipeline_class' => tracker.pipeline_name, + 'tracker_state' => tracker.human_status_name + ) + end + + it 'also loads the entity data' do + expect_next_instance_of(described_class) do |logger| + expect(logger).to receive(:with_entity).once + end + + logger + end + end +end diff --git a/spec/lib/bulk_imports/pipeline/runner_spec.rb b/spec/lib/bulk_imports/pipeline/runner_spec.rb index a88e8fb50d3..72e5e16a5b4 100644 --- a/spec/lib/bulk_imports/pipeline/runner_spec.rb +++ b/spec/lib/bulk_imports/pipeline/runner_spec.rb @@ -55,13 +55,11 @@ RSpec.describe BulkImports::Pipeline::Runner, feature_category: :importers do shared_examples 'failed pipeline' do |exception_class, exception_message| it 'logs import failure' do expect_next_instance_of(BulkImports::Logger) do |logger| + expect(logger).to receive(:with_entity).with(context.entity).and_call_original expect(logger).to receive(:error) .with( a_hash_including( - 'bulk_import_entity_id' => entity.id, 'bulk_import_id' => entity.bulk_import_id, - 'bulk_import_entity_type' => entity.source_type, - 'source_full_path' => entity.source_full_path, 'pipeline_step' => :extractor, 'pipeline_class' => 'BulkImports::MyPipeline', 'exception.class' => exception_class, @@ -69,8 +67,7 @@ RSpec.describe BulkImports::Pipeline::Runner, feature_category: :importers do 'correlation_id' => anything, 'class' => 'BulkImports::MyPipeline', 'message' => 'An object of a pipeline failed to import', - 'exception.backtrace' => anything, - 'source_version' => entity.bulk_import.source_version_info.to_s + 'exception.backtrace' => anything ) ) end @@ -94,6 +91,7 @@ RSpec.describe BulkImports::Pipeline::Runner, feature_category: :importers do it 'logs a warn message and marks entity and tracker as failed' do expect_next_instance_of(BulkImports::Logger) do |logger| + expect(logger).to receive(:with_entity).with(context.entity).and_call_original expect(logger).to receive(:warn) .with( log_params( @@ -198,7 +196,8 @@ RSpec.describe BulkImports::Pipeline::Runner, feature_category: :importers do expect(context.bulk_import).to receive(:touch) expect(context.entity).to receive(:touch) - expect_next_instance_of(Gitlab::Import::Logger) do |logger| + expect_next_instance_of(BulkImports::Logger) do |logger| + expect(logger).to receive(:with_entity).with(context.entity).and_call_original expect(logger).to receive(:info) .with( log_params( @@ -419,6 +418,7 @@ RSpec.describe BulkImports::Pipeline::Runner, feature_category: :importers do entity.fail_op! expect_next_instance_of(BulkImports::Logger) do |logger| + expect(logger).to receive(:with_entity).with(context.entity).and_call_original expect(logger).to receive(:warn) .with( log_params( @@ -436,10 +436,6 @@ RSpec.describe BulkImports::Pipeline::Runner, feature_category: :importers do def log_params(context, extra = {}) { bulk_import_id: context.bulk_import_id, - bulk_import_entity_id: context.entity.id, - bulk_import_entity_type: context.entity.source_type, - source_full_path: entity.source_full_path, - source_version: context.entity.bulk_import.source_version_info.to_s, context_extra: context.extra }.merge(extra) end |