diff options
Diffstat (limited to 'spec')
16 files changed, 183 insertions, 225 deletions
diff --git a/spec/frontend/feature_highlight/feature_highlight_helper_spec.js b/spec/frontend/feature_highlight/feature_highlight_helper_spec.js deleted file mode 100644 index 4609bfc23d7..00000000000 --- a/spec/frontend/feature_highlight/feature_highlight_helper_spec.js +++ /dev/null @@ -1,42 +0,0 @@ -import MockAdapter from 'axios-mock-adapter'; -import { dismiss } from '~/feature_highlight/feature_highlight_helper'; -import { createAlert } from '~/alert'; -import axios from '~/lib/utils/axios_utils'; -import { HTTP_STATUS_CREATED, HTTP_STATUS_INTERNAL_SERVER_ERROR } from '~/lib/utils/http_status'; - -jest.mock('~/alert'); - -describe('feature highlight helper', () => { - describe('dismiss', () => { - let mockAxios; - const endpoint = '/-/callouts/dismiss'; - const highlightId = '123'; - - beforeEach(() => { - mockAxios = new MockAdapter(axios); - }); - - afterEach(() => { - mockAxios.reset(); - }); - - it('calls persistent dismissal endpoint with highlightId', async () => { - mockAxios.onPost(endpoint, { feature_name: highlightId }).replyOnce(HTTP_STATUS_CREATED); - - await expect(dismiss(endpoint, highlightId)).resolves.toEqual(expect.anything()); - }); - - it('triggers an alert when dismiss request fails', async () => { - mockAxios - .onPost(endpoint, { feature_name: highlightId }) - .replyOnce(HTTP_STATUS_INTERNAL_SERVER_ERROR); - - await dismiss(endpoint, highlightId); - - expect(createAlert).toHaveBeenCalledWith({ - message: - 'An error occurred while dismissing the feature highlight. Refresh the page and try dismissing again.', - }); - }); - }); -}); diff --git a/spec/frontend/feature_highlight/feature_highlight_popover_spec.js b/spec/frontend/feature_highlight/feature_highlight_popover_spec.js deleted file mode 100644 index 66ea22cece3..00000000000 --- a/spec/frontend/feature_highlight/feature_highlight_popover_spec.js +++ /dev/null @@ -1,75 +0,0 @@ -import { GlPopover, GlLink, GlButton } from '@gitlab/ui'; -import { mount } from '@vue/test-utils'; -import { nextTick } from 'vue'; -import { POPOVER_TARGET_ID } from '~/feature_highlight/constants'; -import { dismiss } from '~/feature_highlight/feature_highlight_helper'; -import FeatureHighlightPopover from '~/feature_highlight/feature_highlight_popover.vue'; - -jest.mock('~/feature_highlight/feature_highlight_helper'); - -describe('feature_highlight/feature_highlight_popover', () => { - let wrapper; - const props = { - autoDevopsHelpPath: '/help/autodevops', - highlightId: '123', - dismissEndpoint: '/api/dismiss', - }; - - const buildWrapper = (propsData = props) => { - wrapper = mount(FeatureHighlightPopover, { - propsData, - }); - }; - const findPopoverTarget = () => wrapper.find(`#${POPOVER_TARGET_ID}`); - const findPopover = () => wrapper.findComponent(GlPopover); - const findAutoDevopsHelpLink = () => wrapper.findComponent(GlLink); - const findDismissButton = () => wrapper.findComponent(GlButton); - - beforeEach(() => { - buildWrapper(); - }); - - it('renders popover target', () => { - expect(findPopoverTarget().exists()).toBe(true); - }); - - it('renders popover', () => { - expect(findPopover().props()).toMatchObject({ - target: POPOVER_TARGET_ID, - cssClasses: ['feature-highlight-popover'], - container: 'body', - placement: 'right', - boundary: 'viewport', - }); - }); - - it('renders link that points to the autodevops help page', () => { - expect(findAutoDevopsHelpLink().attributes().href).toBe(props.autoDevopsHelpPath); - expect(findAutoDevopsHelpLink().text()).toBe('Auto DevOps'); - }); - - it('renders dismiss button', () => { - expect(findDismissButton().props()).toMatchObject({ - size: 'small', - icon: 'thumb-up', - variant: 'confirm', - }); - }); - - it('dismisses popover when dismiss button is clicked', async () => { - await findDismissButton().trigger('click'); - - expect(findPopover().emitted('close')).toHaveLength(1); - expect(dismiss).toHaveBeenCalledWith(props.dismissEndpoint, props.highlightId); - }); - - describe('when popover is dismissed and hidden', () => { - it('hides the popover target', async () => { - await findDismissButton().trigger('click'); - findPopover().vm.$emit('hidden'); - await nextTick(); - - expect(findPopoverTarget().exists()).toBe(false); - }); - }); -}); diff --git a/spec/frontend/vue_merge_request_widget/components/states/mr_widget_ready_to_merge_spec.js b/spec/frontend/vue_merge_request_widget/components/states/mr_widget_ready_to_merge_spec.js index dbfd3cec76c..1b7338744e8 100644 --- a/spec/frontend/vue_merge_request_widget/components/states/mr_widget_ready_to_merge_spec.js +++ b/spec/frontend/vue_merge_request_widget/components/states/mr_widget_ready_to_merge_spec.js @@ -1,9 +1,10 @@ -import { shallowMount } from '@vue/test-utils'; import Vue, { nextTick } from 'vue'; import { GlSprintf } from '@gitlab/ui'; import VueApollo from 'vue-apollo'; import produce from 'immer'; +import { createMockSubscription as createMockApolloSubscription } from 'mock-apollo-client'; import readyToMergeResponse from 'test_fixtures/graphql/merge_requests/states/ready_to_merge.query.graphql.json'; +import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import waitForPromises from 'helpers/wait_for_promises'; import createMockApollo from 'helpers/mock_apollo_helper'; import readyToMergeQuery from 'ee_else_ce/vue_merge_request_widget/queries/states/ready_to_merge.query.graphql'; @@ -15,6 +16,7 @@ import SquashBeforeMerge from '~/vue_merge_request_widget/components/states/squa import MergeFailedPipelineConfirmationDialog from '~/vue_merge_request_widget/components/states/merge_failed_pipeline_confirmation_dialog.vue'; import { MWPS_MERGE_STRATEGY } from '~/vue_merge_request_widget/constants'; import eventHub from '~/vue_merge_request_widget/event_hub'; +import readyToMergeSubscription from '~/vue_merge_request_widget/queries/states/ready_to_merge.subscription.graphql'; jest.mock('~/lib/utils/simple_poll', () => jest.fn().mockImplementation(jest.requireActual('~/lib/utils/simple_poll').default), @@ -79,6 +81,7 @@ Vue.use(VueApollo); let service; let wrapper; let readyToMergeResponseSpy; +let mockedSubscription; const createReadyToMergeResponse = (customMr) => { return produce(readyToMergeResponse, (draft) => { @@ -87,7 +90,21 @@ const createReadyToMergeResponse = (customMr) => { }; const createComponent = (customConfig = {}, createState = true) => { - wrapper = shallowMount(ReadyToMerge, { + mockedSubscription = createMockApolloSubscription(); + const apolloProvider = createMockApollo([[readyToMergeQuery, readyToMergeResponseSpy]]); + const subscriptionResponse = { + data: { mergeRequestMergeStatusUpdated: { ...readyToMergeResponse.data.project.mergeRequest } }, + }; + subscriptionResponse.data.mergeRequestMergeStatusUpdated.defaultMergeCommitMessage = + 'New default merge commit message'; + + const subscriptionHandlers = [[readyToMergeSubscription, () => mockedSubscription]]; + + subscriptionHandlers.forEach(([query, stream]) => { + apolloProvider.defaultClient.setRequestHandler(query, stream); + }); + + wrapper = shallowMountExtended(ReadyToMerge, { propsData: { mr: createTestMr(customConfig), service, @@ -109,7 +126,7 @@ const createComponent = (customConfig = {}, createState = true) => { CommitEdit, GlSprintf, }, - apolloProvider: createMockApollo([[readyToMergeQuery, readyToMergeResponseSpy]]), + apolloProvider, }); }; @@ -840,4 +857,60 @@ describe('ReadyToMerge', () => { expect(wrapper.text()).not.toContain('Auto-merge enabled'); }); }); + + describe('commit message', () => { + it('updates commit message from subscription', async () => { + createComponent({ mr: { id: 1 } }); + + await waitForPromises(); + + await wrapper.findByTestId('widget_edit_commit_message').vm.$emit('input', true); + + expect(wrapper.findByTestId('merge-commit-message').props('value')).not.toEqual( + 'Updated commit message', + ); + + mockedSubscription.next({ + data: { + mergeRequestMergeStatusUpdated: { + ...readyToMergeResponse.data.project.mergeRequest, + defaultMergeCommitMessage: 'Updated commit message', + }, + }, + }); + + await waitForPromises(); + + expect(wrapper.findByTestId('merge-commit-message').props('value')).toEqual( + 'Updated commit message', + ); + }); + + it('does not update commit message from subscription if commit message has been manually changed', async () => { + createComponent({ mr: { id: 1 } }); + + await waitForPromises(); + + await wrapper.findByTestId('widget_edit_commit_message').vm.$emit('input', true); + + await wrapper + .findByTestId('merge-commit-message') + .vm.$emit('input', 'Manually updated commit message'); + + mockedSubscription.next({ + data: { + mergeRequestMergeStatusUpdated: { + ...readyToMergeResponse.data.project.mergeRequest, + defaultMergeCommitMessage: 'Updated commit message', + }, + }, + }); + + await waitForPromises(); + + expect(wrapper.findByTestId('merge-commit-message').props('value')).toEqual( + 'Manually updated commit message', + ); + }); + }); }); 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 diff --git a/spec/models/notification_recipient_spec.rb b/spec/models/notification_recipient_spec.rb index f19c0a68f87..65bf7aec269 100644 --- a/spec/models/notification_recipient_spec.rb +++ b/spec/models/notification_recipient_spec.rb @@ -440,8 +440,8 @@ RSpec.describe NotificationRecipient, feature_category: :team_planning do described_class.new(user, :participating, custom_action: :issue_due, target: target, project: project) end - it 'returns true' do - expect(recipient.suitable_notification_level?).to eq true + it 'returns false' do + expect(recipient.suitable_notification_level?).to eq false end end end diff --git a/spec/models/notification_setting_spec.rb b/spec/models/notification_setting_spec.rb index 1bb639a5907..cb1bbb91a67 100644 --- a/spec/models/notification_setting_spec.rb +++ b/spec/models/notification_setting_spec.rb @@ -193,7 +193,11 @@ RSpec.describe NotificationSetting do end it 'includes EXCLUDED_WATCHER_EVENTS' do - expect(subject).to include(*described_class::EXCLUDED_WATCHER_EVENTS) + expect(subject).to include( + :push_to_merge_request, + :issue_due, + :success_pipeline + ) end end diff --git a/spec/services/bulk_imports/file_download_service_spec.rb b/spec/services/bulk_imports/file_download_service_spec.rb index 0d9fe96bb64..0c3eef69fa5 100644 --- a/spec/services/bulk_imports/file_download_service_spec.rb +++ b/spec/services/bulk_imports/file_download_service_spec.rb @@ -95,7 +95,6 @@ RSpec.describe BulkImports::FileDownloadService, feature_category: :importers do message: 'Invalid content type', response_code: chunk_code, response_headers: headers, - importer: 'gitlab_migration', last_chunk_context: 'some chunk context' ) diff --git a/spec/services/bulk_imports/process_service_spec.rb b/spec/services/bulk_imports/process_service_spec.rb index f5566819039..a295b170c2f 100644 --- a/spec/services/bulk_imports/process_service_spec.rb +++ b/spec/services/bulk_imports/process_service_spec.rb @@ -205,28 +205,20 @@ RSpec.describe BulkImports::ProcessService, feature_category: :importers do it 'logs an info message for the skipped pipelines' do expect_next_instance_of(BulkImports::Logger) do |logger| + expect(logger).to receive(:with_entity).with(entity).and_call_original.twice + expect(logger).to receive(:info).with( message: 'Pipeline skipped as source instance version not compatible with pipeline', - 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_class: 'PipelineClass4', minimum_source_version: '15.1.0', - maximum_source_version: nil, - source_version: '15.0.0' + maximum_source_version: nil ) expect(logger).to receive(:info).with( message: 'Pipeline skipped as source instance version not compatible with pipeline', - 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_class: 'PipelineClass5', minimum_source_version: '16.0.0', - maximum_source_version: nil, - source_version: '15.0.0' + maximum_source_version: nil ) end diff --git a/spec/workers/bulk_imports/entity_worker_spec.rb b/spec/workers/bulk_imports/entity_worker_spec.rb index 4988a368598..325b31c85db 100644 --- a/spec/workers/bulk_imports/entity_worker_spec.rb +++ b/spec/workers/bulk_imports/entity_worker_spec.rb @@ -73,6 +73,8 @@ RSpec.describe BulkImports::EntityWorker, feature_category: :importers do it 'enqueues the pipeline workers from the next stage and re-enqueues itself' do 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(hash_including('message' => 'Stage starting', 'entity_stage' => 1)) end diff --git a/spec/workers/bulk_imports/export_request_worker_spec.rb b/spec/workers/bulk_imports/export_request_worker_spec.rb index e9d0b6b24b2..2cc6348bb27 100644 --- a/spec/workers/bulk_imports/export_request_worker_spec.rb +++ b/spec/workers/bulk_imports/export_request_worker_spec.rb @@ -72,17 +72,14 @@ RSpec.describe BulkImports::ExportRequestWorker, feature_category: :importers do entity.update!(source_xid: nil) expect_next_instance_of(BulkImports::Logger) do |logger| + expect(logger).to receive(:with_entity).with(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, 'exception.backtrace' => anything, 'exception.class' => 'NoMethodError', 'exception.message' => /^undefined method `model_id' for nil:NilClass/, - 'message' => 'Failed to fetch source entity id', - 'source_version' => entity.bulk_import.source_version_info.to_s + 'message' => 'Failed to fetch source entity id' ) ).twice end @@ -148,7 +145,9 @@ RSpec.describe BulkImports::ExportRequestWorker, feature_category: :importers do entity = create(:bulk_import_entity, bulk_import: bulk_import) error = 'Exhausted error!' - expect_next_instance_of(Gitlab::Import::Logger) do |logger| + expect_next_instance_of(BulkImports::Logger) do |logger| + expect(logger).to receive(:with_entity).with(entity).and_call_original + expect(logger) .to receive(:error) .with(hash_including('message' => "Request to export #{entity.source_type} failed")) diff --git a/spec/workers/bulk_imports/finish_batched_pipeline_worker_spec.rb b/spec/workers/bulk_imports/finish_batched_pipeline_worker_spec.rb index 959b063e061..2dd5b23b3d2 100644 --- a/spec/workers/bulk_imports/finish_batched_pipeline_worker_spec.rb +++ b/spec/workers/bulk_imports/finish_batched_pipeline_worker_spec.rb @@ -49,6 +49,9 @@ RSpec.describe BulkImports::FinishBatchedPipelineWorker, feature_category: :impo it 'marks the tracker as finished' do expect_next_instance_of(BulkImports::Logger) do |logger| + expect(logger).to receive(:with_tracker).with(pipeline_tracker).and_call_original + expect(logger).to receive(:with_entity).with(entity).and_call_original + expect(logger).to receive(:info).with( a_hash_including('message' => 'Tracker finished') ) @@ -96,6 +99,9 @@ RSpec.describe BulkImports::FinishBatchedPipelineWorker, feature_category: :impo it 'fails pipeline tracker and its batches' do expect_next_instance_of(BulkImports::Logger) do |logger| + expect(logger).to receive(:with_tracker).with(pipeline_tracker).and_call_original + expect(logger).to receive(:with_entity).with(entity).and_call_original + expect(logger).to receive(:error).with( a_hash_including('message' => 'Batch stale. Failing batches and tracker') ) diff --git a/spec/workers/bulk_imports/pipeline_worker_spec.rb b/spec/workers/bulk_imports/pipeline_worker_spec.rb index 09f76169a12..19688596a18 100644 --- a/spec/workers/bulk_imports/pipeline_worker_spec.rb +++ b/spec/workers/bulk_imports/pipeline_worker_spec.rb @@ -65,17 +65,9 @@ RSpec.describe BulkImports::PipelineWorker, feature_category: :importers do it 'runs the given pipeline successfully' do expect_next_instance_of(BulkImports::Logger) do |logger| - expect(logger) - .to receive(:info) - .with( - hash_including( - 'pipeline_class' => 'FakePipeline', - '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 - ) - ) + expect(logger).to receive(:with_tracker).with(pipeline_tracker).and_call_original + expect(logger).to receive(:with_entity).with(pipeline_tracker.entity).and_call_original + expect(logger).to receive(:info) end allow(worker).to receive(:jid).and_return('jid') @@ -102,22 +94,9 @@ RSpec.describe BulkImports::PipelineWorker, feature_category: :importers do job = { 'args' => [pipeline_tracker.id, pipeline_tracker.stage, entity.id] } expect_next_instance_of(BulkImports::Logger) do |logger| - expect(logger) - .to receive(:error) - .with( - hash_including( - 'pipeline_class' => 'FakePipeline', - '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, - 'class' => 'BulkImports::PipelineWorker', - 'exception.message' => 'Error!', - 'message' => 'Pipeline failed', - 'source_version' => entity.bulk_import.source_version_info.to_s, - 'importer' => 'gitlab_migration' - ) - ) + expect(logger).to receive(:with_tracker).with(pipeline_tracker).and_call_original + expect(logger).to receive(:with_entity).with(pipeline_tracker.entity).and_call_original + expect(logger).to receive(:error) end expect(Gitlab::ErrorTracking) @@ -125,13 +104,13 @@ RSpec.describe BulkImports::PipelineWorker, feature_category: :importers do .with( instance_of(StandardError), 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_class' => pipeline_tracker.pipeline_name, - 'importer' => 'gitlab_migration', - 'source_version' => entity.bulk_import.source_version_info.to_s + 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_class: pipeline_tracker.pipeline_name, + importer: 'gitlab_migration', + source_version: entity.bulk_import.source_version_info.to_s ) ) @@ -302,16 +281,7 @@ RSpec.describe BulkImports::PipelineWorker, feature_category: :importers do expect(logger) .to receive(:info) - .with( - hash_including( - 'pipeline_class' => 'FakePipeline', - '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, - 'message' => 'Skipping pipeline due to failed entity' - ) - ) + .with(hash_including(message: 'Skipping pipeline due to failed entity')) end worker.perform(pipeline_tracker.id, pipeline_tracker.stage, entity.id) @@ -350,17 +320,9 @@ RSpec.describe BulkImports::PipelineWorker, feature_category: :importers do end expect_next_instance_of(BulkImports::Logger) do |logger| - expect(logger) - .to receive(:info) - .with( - hash_including( - 'pipeline_class' => 'FakePipeline', - '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 - ) - ) + expect(logger).to receive(:with_tracker).and_call_original + expect(logger).to receive(:with_entity).and_call_original + expect(logger).to receive(:info) end expect(described_class) diff --git a/spec/workers/bulk_imports/stuck_import_worker_spec.rb b/spec/workers/bulk_imports/stuck_import_worker_spec.rb index 4bcc72326c7..09fd1e1b524 100644 --- a/spec/workers/bulk_imports/stuck_import_worker_spec.rb +++ b/spec/workers/bulk_imports/stuck_import_worker_spec.rb @@ -48,16 +48,12 @@ RSpec.describe BulkImports::StuckImportWorker, feature_category: :importers do it 'updates the status of bulk import entities to timeout' do expect_next_instance_of(BulkImports::Logger) do |logger| allow(logger).to receive(:error) - expect(logger).to receive(:error).with( - message: 'BulkImports::Entity stale', - bulk_import_entity_id: stale_created_bulk_import_entity.id, - bulk_import_id: stale_created_bulk_import_entity.bulk_import_id - ) - expect(logger).to receive(:error).with( - message: 'BulkImports::Entity stale', - bulk_import_entity_id: stale_started_bulk_import_entity.id, - bulk_import_id: stale_started_bulk_import_entity.bulk_import_id - ) + + expect(logger).to receive(:with_entity).with(stale_created_bulk_import_entity).and_call_original + expect(logger).to receive(:error).with(message: 'BulkImports::Entity stale') + + expect(logger).to receive(:with_entity).with(stale_started_bulk_import_entity).and_call_original + expect(logger).to receive(:error).with(message: 'BulkImports::Entity stale') end expect { subject }.to change { stale_created_bulk_import_entity.reload.status_name }.from(:created).to(:timeout) |