diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
commit | 0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch) | |
tree | 7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /spec/services/bulk_imports | |
parent | 72123183a20411a36d607d70b12d57c484394c8e (diff) |
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'spec/services/bulk_imports')
4 files changed, 245 insertions, 22 deletions
diff --git a/spec/services/bulk_imports/create_pipeline_trackers_service_spec.rb b/spec/services/bulk_imports/create_pipeline_trackers_service_spec.rb new file mode 100644 index 00000000000..d7b00ba04ab --- /dev/null +++ b/spec/services/bulk_imports/create_pipeline_trackers_service_spec.rb @@ -0,0 +1,168 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BulkImports::CreatePipelineTrackersService do + describe '#execute!' do + context 'when entity is group' do + it 'creates trackers for group entity' do + bulk_import = create(:bulk_import) + entity = create(:bulk_import_entity, :group_entity, bulk_import: bulk_import) + + described_class.new(entity).execute! + + expect(entity.trackers.to_a).to include( + have_attributes( + stage: 0, status_name: :created, relation: BulkImports::Groups::Pipelines::GroupPipeline.to_s + ), + have_attributes( + stage: 1, status_name: :created, relation: BulkImports::Groups::Pipelines::GroupAttributesPipeline.to_s + ) + ) + end + end + + context 'when entity is project' do + it 'creates trackers for project entity' do + bulk_import = create(:bulk_import) + entity = create(:bulk_import_entity, :project_entity, bulk_import: bulk_import) + + described_class.new(entity).execute! + + expect(entity.trackers.to_a).to include( + have_attributes( + stage: 0, status_name: :created, relation: BulkImports::Projects::Pipelines::ProjectPipeline.to_s + ), + have_attributes( + stage: 1, status_name: :created, relation: BulkImports::Projects::Pipelines::RepositoryPipeline.to_s + ) + ) + end + end + + context 'when tracker configuration has a minimum version defined' do + before do + allow_next_instance_of(BulkImports::Groups::Stage) do |stage| + allow(stage).to receive(:config).and_return( + { + pipeline1: { pipeline: 'PipelineClass1', stage: 0 }, + pipeline2: { pipeline: 'PipelineClass2', stage: 1, minimum_source_version: '14.10.0' }, + pipeline3: { pipeline: 'PipelineClass3', stage: 1, minimum_source_version: '15.0.0' }, + pipeline5: { pipeline: 'PipelineClass4', stage: 1, minimum_source_version: '15.1.0' }, + pipeline6: { pipeline: 'PipelineClass5', stage: 1, minimum_source_version: '16.0.0' } + } + ) + end + end + + context 'when the source instance version is older than the tracker mininum version' do + let_it_be(:bulk_import) { create(:bulk_import, source_version: '15.0.0') } + let_it_be(:entity) { create(:bulk_import_entity, :group_entity, bulk_import: bulk_import) } + + it 'creates trackers as skipped if version requirement does not meet' do + described_class.new(entity).execute! + + expect(entity.trackers.collect { |tracker| [tracker.status_name, tracker.relation] }).to contain_exactly( + [:created, 'PipelineClass1'], + [:created, 'PipelineClass2'], + [:created, 'PipelineClass3'], + [:skipped, 'PipelineClass4'], + [:skipped, 'PipelineClass5'] + ) + end + + it 'logs an info message for the skipped pipelines' do + expect_next_instance_of(Gitlab::Import::Logger) do |logger| + expect(logger).to receive(:info).with({ + message: 'Pipeline skipped as source instance version not compatible with pipeline', + entity_id: entity.id, + pipeline_name: 'PipelineClass4', + minimum_source_version: '15.1.0', + maximum_source_version: nil, + source_version: '15.0.0' + }) + + expect(logger).to receive(:info).with({ + message: 'Pipeline skipped as source instance version not compatible with pipeline', + entity_id: entity.id, + pipeline_name: 'PipelineClass5', + minimum_source_version: '16.0.0', + maximum_source_version: nil, + source_version: '15.0.0' + }) + end + + described_class.new(entity).execute! + end + end + + context 'when the source instance version is undefined' do + it 'creates trackers as created' do + bulk_import = create(:bulk_import, source_version: nil) + entity = create(:bulk_import_entity, :group_entity, bulk_import: bulk_import) + + described_class.new(entity).execute! + + expect(entity.trackers.collect { |tracker| [tracker.status_name, tracker.relation] }).to contain_exactly( + [:created, 'PipelineClass1'], + [:created, 'PipelineClass2'], + [:created, 'PipelineClass3'], + [:created, 'PipelineClass4'], + [:created, 'PipelineClass5'] + ) + end + end + end + + context 'when tracker configuration has a maximum version defined' do + before do + allow_next_instance_of(BulkImports::Groups::Stage) do |stage| + allow(stage).to receive(:config).and_return( + { + pipeline1: { pipeline: 'PipelineClass1', stage: 0 }, + pipeline2: { pipeline: 'PipelineClass2', stage: 1, maximum_source_version: '14.10.0' }, + pipeline3: { pipeline: 'PipelineClass3', stage: 1, maximum_source_version: '15.0.0' }, + pipeline5: { pipeline: 'PipelineClass4', stage: 1, maximum_source_version: '15.1.0' }, + pipeline6: { pipeline: 'PipelineClass5', stage: 1, maximum_source_version: '16.0.0' } + } + ) + end + end + + context 'when the source instance version is older than the tracker maximum version' do + it 'creates trackers as skipped if version requirement does not meet' do + bulk_import = create(:bulk_import, source_version: '15.0.0') + entity = create(:bulk_import_entity, :group_entity, bulk_import: bulk_import) + + described_class.new(entity).execute! + + expect(entity.trackers.collect { |tracker| [tracker.status_name, tracker.relation] }).to contain_exactly( + [:created, 'PipelineClass1'], + [:skipped, 'PipelineClass2'], + [:created, 'PipelineClass3'], + [:created, 'PipelineClass4'], + [:created, 'PipelineClass5'] + ) + end + end + + context 'when the source instance version is a patch version' do + it 'creates trackers with the same status as the non-patch source version' do + bulk_import_1 = create(:bulk_import, source_version: '15.0.1') + entity_1 = create(:bulk_import_entity, :group_entity, bulk_import: bulk_import_1) + + bulk_import_2 = create(:bulk_import, source_version: '15.0.0') + entity_2 = create(:bulk_import_entity, :group_entity, bulk_import: bulk_import_2) + + described_class.new(entity_1).execute! + described_class.new(entity_2).execute! + + trackers_1 = entity_1.trackers.collect { |tracker| [tracker.status_name, tracker.relation] } + trackers_2 = entity_2.trackers.collect { |tracker| [tracker.status_name, tracker.relation] } + + expect(trackers_1).to eq(trackers_2) + end + end + end + end +end diff --git a/spec/services/bulk_imports/file_export_service_spec.rb b/spec/services/bulk_imports/file_export_service_spec.rb index 94efceff6c6..453fc1d0c0d 100644 --- a/spec/services/bulk_imports/file_export_service_spec.rb +++ b/spec/services/bulk_imports/file_export_service_spec.rb @@ -4,39 +4,34 @@ require 'spec_helper' RSpec.describe BulkImports::FileExportService do let_it_be(:project) { create(:project) } - let_it_be(:export_path) { Dir.mktmpdir } - let_it_be(:relation) { BulkImports::FileTransfer::BaseConfig::UPLOADS_RELATION } - - subject(:service) { described_class.new(project, export_path, relation) } describe '#execute' do - it 'executes export service and archives exported data' do - expect_next_instance_of(BulkImports::UploadsExportService) do |service| - expect(service).to receive(:execute) - end + it 'executes export service and archives exported data for each file relation' do + relations = { + 'uploads' => BulkImports::UploadsExportService, + 'lfs_objects' => BulkImports::LfsObjectsExportService, + 'repository' => BulkImports::RepositoryBundleExportService, + 'design' => BulkImports::RepositoryBundleExportService + } - expect(subject).to receive(:tar_cf).with(archive: File.join(export_path, 'uploads.tar'), dir: export_path) + relations.each do |relation, klass| + Dir.mktmpdir do |export_path| + service = described_class.new(project, export_path, relation) - subject.execute - end + expect_next_instance_of(klass) do |service| + expect(service).to receive(:execute) + end - context 'when relation is lfs objects' do - let_it_be(:relation) { BulkImports::FileTransfer::ProjectConfig::LFS_OBJECTS_RELATION } + expect(service).to receive(:tar_cf).with(archive: File.join(export_path, "#{relation}.tar"), dir: export_path) - it 'executes lfs objects export service' do - expect_next_instance_of(BulkImports::LfsObjectsExportService) do |service| - expect(service).to receive(:execute) + service.execute end - - expect(subject).to receive(:tar_cf).with(archive: File.join(export_path, 'lfs_objects.tar'), dir: export_path) - - subject.execute end end context 'when unsupported relation is passed' do it 'raises an error' do - service = described_class.new(project, export_path, 'unsupported') + service = described_class.new(project, nil, 'unsupported') expect { service.execute }.to raise_error(BulkImports::Error, 'Unsupported relation export type') end @@ -45,7 +40,9 @@ RSpec.describe BulkImports::FileExportService do describe '#exported_filename' do it 'returns filename of the exported file' do - expect(subject.exported_filename).to eq('uploads.tar') + service = described_class.new(project, nil, 'uploads') + + expect(service.exported_filename).to eq('uploads.tar') end end end diff --git a/spec/services/bulk_imports/lfs_objects_export_service_spec.rb b/spec/services/bulk_imports/lfs_objects_export_service_spec.rb index 5ae54ed309b..894789c7941 100644 --- a/spec/services/bulk_imports/lfs_objects_export_service_spec.rb +++ b/spec/services/bulk_imports/lfs_objects_export_service_spec.rb @@ -53,6 +53,18 @@ RSpec.describe BulkImports::LfsObjectsExportService do ) end + context 'when lfs object has file on disk missing' do + it 'does not attempt to copy non-existent file' do + FileUtils.rm(lfs_object.file.path) + + expect(service).not_to receive(:copy_files) + + service.execute + + expect(File).not_to exist(File.join(export_path, lfs_object.oid)) + end + end + context 'when lfs object is remotely stored' do let(:lfs_object) { create(:lfs_object, :object_storage) } diff --git a/spec/services/bulk_imports/repository_bundle_export_service_spec.rb b/spec/services/bulk_imports/repository_bundle_export_service_spec.rb new file mode 100644 index 00000000000..a7d98a7474a --- /dev/null +++ b/spec/services/bulk_imports/repository_bundle_export_service_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BulkImports::RepositoryBundleExportService do + let(:project) { create(:project) } + let(:export_path) { Dir.mktmpdir } + + subject(:service) { described_class.new(repository, export_path, export_filename) } + + after do + FileUtils.remove_entry(export_path) if Dir.exist?(export_path) + end + + describe '#execute' do + shared_examples 'repository export' do + context 'when repository exists' do + it 'bundles repository to disk' do + allow(repository).to receive(:exists?).and_return(true) + expect(repository).to receive(:bundle_to_disk).with(File.join(export_path, "#{export_filename}.bundle")) + + service.execute + end + end + + context 'when repository does not exist' do + it 'does not bundle repository to disk' do + allow(repository).to receive(:exists?).and_return(false) + expect(repository).not_to receive(:bundle_to_disk) + + service.execute + end + end + end + + include_examples 'repository export' do + let(:repository) { project.repository } + let(:export_filename) { 'repository' } + end + + include_examples 'repository export' do + let(:repository) { project.design_repository } + let(:export_filename) { 'design' } + end + end +end |