diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-01 03:10:57 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-01 03:10:57 +0300 |
commit | 533fed8bd825f93b4b43bd41d41caa38cfc6ae55 (patch) | |
tree | bdc5458e4fb19126f705b0786c055d1b9c118748 /spec/lib | |
parent | 24fb09b2eb3f4703b09eef3c9bbf842cd055626a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
5 files changed, 144 insertions, 10 deletions
diff --git a/spec/lib/api/entities/bulk_imports/entity_failure_spec.rb b/spec/lib/api/entities/bulk_imports/entity_failure_spec.rb index 0132102b117..217e6c11630 100644 --- a/spec/lib/api/entities/bulk_imports/entity_failure_spec.rb +++ b/spec/lib/api/entities/bulk_imports/entity_failure_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe API::Entities::BulkImports::EntityFailure do +RSpec.describe API::Entities::BulkImports::EntityFailure, feature_category: :importers do let_it_be(:failure) { create(:bulk_import_failure) } subject { described_class.new(failure).as_json } @@ -10,11 +10,11 @@ RSpec.describe API::Entities::BulkImports::EntityFailure do it 'has the correct attributes' do expect(subject).to include( :relation, - :step, - :exception_class, :exception_message, + :exception_class, :correlation_id_value, - :created_at + :source_url, + :source_title ) end diff --git a/spec/lib/bulk_imports/pipeline/runner_spec.rb b/spec/lib/bulk_imports/pipeline/runner_spec.rb index aa31f38cd94..01adde79740 100644 --- a/spec/lib/bulk_imports/pipeline/runner_spec.rb +++ b/spec/lib/bulk_imports/pipeline/runner_spec.rb @@ -43,7 +43,9 @@ RSpec.describe BulkImports::Pipeline::Runner, feature_category: :importers do stub_const('BulkImports::MyPipeline', pipeline) end - let_it_be_with_reload(:entity) { create(:bulk_import_entity) } + let_it_be(:bulk_import) { create(:bulk_import) } + let_it_be(:configuration) { create(:bulk_import_configuration, bulk_import: bulk_import) } + let_it_be_with_reload(:entity) { create(:bulk_import_entity, bulk_import: bulk_import) } let(:tracker) { create(:bulk_import_tracker, entity: entity) } let(:context) { BulkImports::Pipeline::Context.new(tracker, extra: :data) } @@ -119,6 +121,56 @@ RSpec.describe BulkImports::Pipeline::Runner, feature_category: :importers do expect(entity.failed?).to eq(false) end end + + context 'when failure happens during loader' do + before do + allow(tracker).to receive(:pipeline_class).and_return(BulkImports::MyPipeline) + allow(BulkImports::MyPipeline).to receive(:relation).and_return(relation) + + allow_next_instance_of(BulkImports::Extractor) do |extractor| + allow(extractor).to receive(:extract).with(context).and_return(extracted_data) + end + + allow_next_instance_of(BulkImports::Transformer) do |transformer| + allow(transformer).to receive(:transform).with(context, extracted_data.data.first).and_return(entry) + end + + allow_next_instance_of(BulkImports::Loader) do |loader| + allow(loader).to receive(:load).with(context, entry).and_raise(StandardError, 'Error!') + end + end + + context 'when entry has title' do + let(:relation) { 'issues' } + let(:entry) { Issue.new(iid: 1, title: 'hello world') } + + it 'creates failure record with source url and title' do + subject.run + + failure = entity.failures.first + expected_source_url = File.join(configuration.url, 'groups', entity.source_full_path, '-', 'issues', '1') + + expect(failure).to be_present + expect(failure.source_url).to eq(expected_source_url) + expect(failure.source_title).to eq('hello world') + end + end + + context 'when entry has name' do + let(:relation) { 'boards' } + let(:entry) { Board.new(name: 'hello world') } + + it 'creates failure record with name' do + subject.run + + failure = entity.failures.first + + expect(failure).to be_present + expect(failure.source_url).to be_nil + expect(failure.source_title).to eq('hello world') + end + end + end end describe 'pipeline runner' do @@ -363,7 +415,11 @@ RSpec.describe BulkImports::Pipeline::Runner, feature_category: :importers do def extracted_data(has_next_page: false) BulkImports::Pipeline::ExtractedData.new( - data: { foo: :bar }, + data: { + 'foo' => 'bar', + 'title' => 'hello world', + 'iid' => 1 + }, page_info: { 'has_next_page' => has_next_page, 'next_page' => has_next_page ? 'cursor' : nil diff --git a/spec/lib/bulk_imports/projects/pipelines/container_expiration_policy_pipeline_spec.rb b/spec/lib/bulk_imports/projects/pipelines/container_expiration_policy_pipeline_spec.rb index 9dac8e45ef9..334c2004b59 100644 --- a/spec/lib/bulk_imports/projects/pipelines/container_expiration_policy_pipeline_spec.rb +++ b/spec/lib/bulk_imports/projects/pipelines/container_expiration_policy_pipeline_spec.rb @@ -2,10 +2,10 @@ require 'spec_helper' -RSpec.describe BulkImports::Projects::Pipelines::ContainerExpirationPolicyPipeline do +RSpec.describe BulkImports::Projects::Pipelines::ContainerExpirationPolicyPipeline, feature_category: :importers do let_it_be(:project) { create(:project) } let_it_be(:entity) { create(:bulk_import_entity, :project_entity, project: project) } - let_it_be(:tracker) { create(:bulk_import_tracker, entity: entity) } + let_it_be(:tracker) { create(:bulk_import_tracker, entity: entity, pipeline_name: described_class) } let_it_be(:context) { BulkImports::Pipeline::Context.new(tracker) } let_it_be(:policy) do diff --git a/spec/lib/bulk_imports/projects/pipelines/external_pull_requests_pipeline_spec.rb b/spec/lib/bulk_imports/projects/pipelines/external_pull_requests_pipeline_spec.rb index b7197814f9c..f00da47d9f5 100644 --- a/spec/lib/bulk_imports/projects/pipelines/external_pull_requests_pipeline_spec.rb +++ b/spec/lib/bulk_imports/projects/pipelines/external_pull_requests_pipeline_spec.rb @@ -2,11 +2,11 @@ require 'spec_helper' -RSpec.describe BulkImports::Projects::Pipelines::ExternalPullRequestsPipeline do +RSpec.describe BulkImports::Projects::Pipelines::ExternalPullRequestsPipeline, feature_category: :importers do let_it_be(:project) { create(:project) } let_it_be(:bulk_import) { create(:bulk_import) } let_it_be(:entity) { create(:bulk_import_entity, :project_entity, project: project, bulk_import: bulk_import) } - let_it_be(:tracker) { create(:bulk_import_tracker, entity: entity) } + let_it_be(:tracker) { create(:bulk_import_tracker, entity: entity, pipeline_name: described_class) } let_it_be(:context) { BulkImports::Pipeline::Context.new(tracker) } let(:attributes) { {} } diff --git a/spec/lib/bulk_imports/source_url_builder_spec.rb b/spec/lib/bulk_imports/source_url_builder_spec.rb new file mode 100644 index 00000000000..2c0e042314b --- /dev/null +++ b/spec/lib/bulk_imports/source_url_builder_spec.rb @@ -0,0 +1,78 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BulkImports::SourceUrlBuilder, feature_category: :importers do + let_it_be(:bulk_import) { create(:bulk_import) } + let_it_be(:configuration) { create(:bulk_import_configuration, bulk_import: bulk_import) } + + let(:entity) { create(:bulk_import_entity, bulk_import: bulk_import) } + let(:tracker) { create(:bulk_import_tracker, entity: entity) } + let(:context) { BulkImports::Pipeline::Context.new(tracker) } + let(:entry) { Issue.new(iid: 1, title: 'hello world') } + + describe '#url' do + subject { described_class.new(context, entry) } + + before do + allow(subject).to receive(:relation).and_return('issues') + end + + context 'when relation is allowed' do + context 'when entity is a group' do + it 'returns the url specific to groups' do + expected_url = File.join( + configuration.url, + 'groups', + entity.source_full_path, + '-', + 'issues', + '1' + ) + + expect(subject.url).to eq(expected_url) + end + end + + context 'when entity is a project' do + let(:entity) { create(:bulk_import_entity, :project_entity, bulk_import: bulk_import) } + + it 'returns the url' do + expected_url = File.join( + configuration.url, + entity.source_full_path, + '-', + 'issues', + '1' + ) + + expect(subject.url).to eq(expected_url) + end + end + end + + context 'when entry is not an ApplicationRecord' do + let(:entry) { 'not an ApplicationRecord' } + + it 'returns nil' do + expect(subject.url).to be_nil + end + end + + context 'when relation is not allowed' do + it 'returns nil' do + allow(subject).to receive(:relation).and_return('not_allowed') + + expect(subject.url).to be_nil + end + end + + context 'when entry has no iid' do + let(:entry) { Issue.new } + + it 'returns nil' do + expect(subject.url).to be_nil + end + end + end +end |