diff options
Diffstat (limited to 'spec/models/bulk_imports')
-rw-r--r-- | spec/models/bulk_imports/entity_spec.rb | 51 | ||||
-rw-r--r-- | spec/models/bulk_imports/export_status_spec.rb | 30 | ||||
-rw-r--r-- | spec/models/bulk_imports/failure_spec.rb | 36 |
3 files changed, 105 insertions, 12 deletions
diff --git a/spec/models/bulk_imports/entity_spec.rb b/spec/models/bulk_imports/entity_spec.rb index 874009d552a..f4f2b174a7b 100644 --- a/spec/models/bulk_imports/entity_spec.rb +++ b/spec/models/bulk_imports/entity_spec.rb @@ -46,6 +46,8 @@ RSpec.describe BulkImports::Entity, type: :model do end it 'is invalid as a project_entity' do + stub_feature_flags(bulk_import_projects: true) + entity = build(:bulk_import_entity, :project_entity, group: build(:group), project: nil) expect(entity).not_to be_valid @@ -55,6 +57,8 @@ RSpec.describe BulkImports::Entity, type: :model do context 'when associated with a project and no group' do it 'is valid' do + stub_feature_flags(bulk_import_projects: true) + entity = build(:bulk_import_entity, :project_entity, group: nil, project: build(:project)) expect(entity).to be_valid @@ -84,6 +88,8 @@ RSpec.describe BulkImports::Entity, type: :model do context 'when the parent is a project import' do it 'is invalid' do + stub_feature_flags(bulk_import_projects: true) + entity = build(:bulk_import_entity, parent: build(:bulk_import_entity, :project_entity)) expect(entity).not_to be_valid @@ -124,6 +130,39 @@ RSpec.describe BulkImports::Entity, type: :model do .to include('Import failed: Destination cannot be a subgroup of the source group. Change the destination and try again.') end end + + context 'when bulk_import_projects feature flag is disabled and source_type is a project_entity' do + it 'is invalid' do + stub_feature_flags(bulk_import_projects: false) + + entity = build(:bulk_import_entity, :project_entity) + + expect(entity).not_to be_valid + expect(entity.errors[:base]).to include('invalid entity source type') + end + end + + context 'when bulk_import_projects feature flag is enabled and source_type is a project_entity' do + it 'is valid' do + stub_feature_flags(bulk_import_projects: true) + + entity = build(:bulk_import_entity, :project_entity) + + expect(entity).to be_valid + end + end + + context 'when bulk_import_projects feature flag is enabled on root ancestor level and source_type is a project_entity' do + it 'is valid' do + top_level_namespace = create(:group) + + stub_feature_flags(bulk_import_projects: top_level_namespace) + + entity = build(:bulk_import_entity, :project_entity, destination_namespace: top_level_namespace.full_path) + + expect(entity).to be_valid + end + end end describe '#encoded_source_full_path' do @@ -209,7 +248,7 @@ RSpec.describe BulkImports::Entity, type: :model do it 'returns group export relations url' do entity = build(:bulk_import_entity, :group_entity) - expect(entity.export_relations_url_path).to eq("/groups/#{entity.encoded_source_full_path}/export_relations") + expect(entity.export_relations_url_path).to eq("/groups/#{entity.source_xid}/export_relations") end end @@ -217,7 +256,7 @@ RSpec.describe BulkImports::Entity, type: :model do it 'returns project export relations url' do entity = build(:bulk_import_entity, :project_entity) - expect(entity.export_relations_url_path).to eq("/projects/#{entity.encoded_source_full_path}/export_relations") + expect(entity.export_relations_url_path).to eq("/projects/#{entity.source_xid}/export_relations") end end end @@ -227,7 +266,7 @@ RSpec.describe BulkImports::Entity, type: :model do entity = build(:bulk_import_entity) expect(entity.relation_download_url_path('test')) - .to eq("/groups/#{entity.encoded_source_full_path}/export_relations/download?relation=test") + .to eq("/groups/#{entity.source_xid}/export_relations/download?relation=test") end end @@ -263,15 +302,15 @@ RSpec.describe BulkImports::Entity, type: :model do describe '#base_resource_url_path' do it 'returns base entity url path' do - entity = build(:bulk_import_entity) + entity = build(:bulk_import_entity, source_xid: nil) - expect(entity.base_resource_url_path).to eq("/groups/#{entity.encoded_source_full_path}") + expect(entity.base_resource_path).to eq("/groups/#{entity.encoded_source_full_path}") end end describe '#wiki_url_path' do it 'returns entity wiki url path' do - entity = build(:bulk_import_entity) + entity = build(:bulk_import_entity, source_xid: nil) expect(entity.wikis_url_path).to eq("/groups/#{entity.encoded_source_full_path}/wikis") end diff --git a/spec/models/bulk_imports/export_status_spec.rb b/spec/models/bulk_imports/export_status_spec.rb index 6ade82409dc..0921c3bdce2 100644 --- a/spec/models/bulk_imports/export_status_spec.rb +++ b/spec/models/bulk_imports/export_status_spec.rb @@ -157,12 +157,36 @@ RSpec.describe BulkImports::ExportStatus do end context 'when something goes wrong during export status fetch' do - it 'returns exception class as error' do + let(:exception) { BulkImports::NetworkError.new('Error!') } + + before do allow_next_instance_of(BulkImports::Clients::HTTP) do |client| - allow(client).to receive(:get).and_raise(StandardError, 'Error!') + allow(client).to receive(:get).once.and_raise(exception) end + end + + it 'raises RetryPipelineError' do + allow(exception).to receive(:retriable?).with(tracker).and_return(true) + + expect { subject.failed? }.to raise_error(BulkImports::RetryPipelineError) + end - expect(subject.error).to eq('Error!') + context 'when error is not retriable' do + it 'returns exception class as error' do + expect(subject.error).to eq('Error!') + expect(subject.failed?).to eq(true) + end + end + + context 'when error raised is not a network error' do + it 'returns exception class as error' do + allow_next_instance_of(BulkImports::Clients::HTTP) do |client| + allow(client).to receive(:get).once.and_raise(StandardError, 'Standard Error!') + end + + expect(subject.error).to eq('Standard Error!') + expect(subject.failed?).to eq(true) + end end end end diff --git a/spec/models/bulk_imports/failure_spec.rb b/spec/models/bulk_imports/failure_spec.rb index cde62659a48..b3fd60ba348 100644 --- a/spec/models/bulk_imports/failure_spec.rb +++ b/spec/models/bulk_imports/failure_spec.rb @@ -3,15 +3,45 @@ require 'spec_helper' RSpec.describe BulkImports::Failure, type: :model do + let(:failure) { create(:bulk_import_failure) } + describe 'associations' do it { is_expected.to belong_to(:entity).required } end describe 'validations' do - before do - create(:bulk_import_failure) + it { is_expected.to validate_presence_of(:entity) } + end + + describe '#relation' do + context 'when pipeline class is valid' do + it 'returns pipeline defined relation' do + failure.update!(pipeline_class: 'BulkImports::Common::Pipelines::WikiPipeline') + + expect(failure.relation).to eq('wiki') + end end - it { is_expected.to validate_presence_of(:entity) } + context 'when pipeline class is invalid' do + it 'returns default relation' do + failure.update!(pipeline_class: 'foobar') + + expect(failure.relation).to eq('foobar') + end + + context 'when pipeline class is outside of BulkImports namespace' do + it 'returns default relation' do + failure.update!(pipeline_class: 'Gitlab::ImportExport::Importer') + + expect(failure.relation).to eq('importer') + end + end + + it 'returns demodulized, underscored, chomped string' do + failure.update!(pipeline_class: 'BulkImports::Pipelines::Test::TestRelationPipeline') + + expect(failure.relation).to eq('test_relation') + end + end end end |