diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 12:16:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 12:16:11 +0300 |
commit | edaa33dee2ff2f7ea3fac488d41558eb5f86d68c (patch) | |
tree | 11f143effbfeba52329fb7afbd05e6e2a3790241 /spec/lib/bulk_imports | |
parent | d8a5691316400a0f7ec4f83832698f1988eb27c1 (diff) |
Add latest changes from gitlab-org/gitlab@14-7-stable-eev14.7.0-rc42
Diffstat (limited to 'spec/lib/bulk_imports')
3 files changed, 55 insertions, 9 deletions
diff --git a/spec/lib/bulk_imports/common/extractors/ndjson_extractor_spec.rb b/spec/lib/bulk_imports/common/extractors/ndjson_extractor_spec.rb index bd306233de8..d6e19a5fc85 100644 --- a/spec/lib/bulk_imports/common/extractors/ndjson_extractor_spec.rb +++ b/spec/lib/bulk_imports/common/extractors/ndjson_extractor_spec.rb @@ -16,7 +16,7 @@ RSpec.describe BulkImports::Common::Extractors::NdjsonExtractor do before do allow(FileUtils).to receive(:remove_entry).with(any_args).and_call_original - subject.instance_variable_set(:@tmp_dir, tmpdir) + subject.instance_variable_set(:@tmpdir, tmpdir) end after(:all) do @@ -43,11 +43,11 @@ RSpec.describe BulkImports::Common::Extractors::NdjsonExtractor do end end - describe '#remove_tmp_dir' do + describe '#remove_tmpdir' do it 'removes tmp dir' do expect(FileUtils).to receive(:remove_entry).with(tmpdir).once - subject.remove_tmp_dir + subject.remove_tmpdir end end end diff --git a/spec/lib/bulk_imports/common/pipelines/uploads_pipeline_spec.rb b/spec/lib/bulk_imports/common/pipelines/uploads_pipeline_spec.rb index 3b5ea131d0d..9d43bb3ebfb 100644 --- a/spec/lib/bulk_imports/common/pipelines/uploads_pipeline_spec.rb +++ b/spec/lib/bulk_imports/common/pipelines/uploads_pipeline_spec.rb @@ -3,10 +3,10 @@ require 'spec_helper' RSpec.describe BulkImports::Common::Pipelines::UploadsPipeline do - let_it_be(:tmpdir) { Dir.mktmpdir } let_it_be(:project) { create(:project) } let_it_be(:group) { create(:group) } + let(:tmpdir) { Dir.mktmpdir } let(:uploads_dir_path) { File.join(tmpdir, '72a497a02fe3ee09edae2ed06d390038') } let(:upload_file_path) { File.join(uploads_dir_path, 'upload.txt')} let(:tracker) { create(:bulk_import_tracker, entity: entity) } @@ -80,10 +80,10 @@ RSpec.describe BulkImports::Common::Pipelines::UploadsPipeline do .with( configuration: context.configuration, relative_url: "/#{entity.pluralized_name}/test/export_relations/download?relation=uploads", - dir: tmpdir, + tmpdir: tmpdir, filename: 'uploads.tar.gz') .and_return(download_service) - expect(BulkImports::FileDecompressionService).to receive(:new).with(dir: tmpdir, filename: 'uploads.tar.gz').and_return(decompression_service) + expect(BulkImports::FileDecompressionService).to receive(:new).with(tmpdir: tmpdir, filename: 'uploads.tar.gz').and_return(decompression_service) expect(BulkImports::ArchiveExtractionService).to receive(:new).with(tmpdir: tmpdir, filename: 'uploads.tar').and_return(extraction_service) expect(download_service).to receive(:execute) @@ -123,6 +123,31 @@ RSpec.describe BulkImports::Common::Pipelines::UploadsPipeline do end end end + + describe '#after_run' do + before do + allow(Dir).to receive(:mktmpdir).with('bulk_imports').and_return(tmpdir) + end + + it 'removes tmp dir' do + allow(FileUtils).to receive(:remove_entry).and_call_original + expect(FileUtils).to receive(:remove_entry).with(tmpdir).and_call_original + + pipeline.after_run(nil) + + expect(Dir.exist?(tmpdir)).to eq(false) + end + + context 'when dir does not exist' do + it 'does not attempt to remove tmpdir' do + FileUtils.remove_entry(tmpdir) + + expect(FileUtils).not_to receive(:remove_entry).with(tmpdir) + + pipeline.after_run(nil) + end + end + end end context 'when importing to group' do diff --git a/spec/lib/bulk_imports/projects/pipelines/project_attributes_pipeline_spec.rb b/spec/lib/bulk_imports/projects/pipelines/project_attributes_pipeline_spec.rb index 11c475318bb..df7ff5b8062 100644 --- a/spec/lib/bulk_imports/projects/pipelines/project_attributes_pipeline_spec.rb +++ b/spec/lib/bulk_imports/projects/pipelines/project_attributes_pipeline_spec.rb @@ -56,7 +56,7 @@ RSpec.describe BulkImports::Projects::Pipelines::ProjectAttributesPipeline do subject(:pipeline) { described_class.new(context) } before do - allow(Dir).to receive(:mktmpdir).and_return(tmpdir) + allow(Dir).to receive(:mktmpdir).with('bulk_imports').and_return(tmpdir) end after do @@ -95,13 +95,13 @@ RSpec.describe BulkImports::Projects::Pipelines::ProjectAttributesPipeline do .with( configuration: context.configuration, relative_url: "/#{entity.pluralized_name}/#{entity.source_full_path}/export_relations/download?relation=self", - dir: tmpdir, + tmpdir: tmpdir, filename: 'self.json.gz') .and_return(file_download_service) expect(BulkImports::FileDecompressionService) .to receive(:new) - .with(dir: tmpdir, filename: 'self.json.gz') + .with(tmpdir: tmpdir, filename: 'self.json.gz') .and_return(file_decompression_service) expect(file_download_service).to receive(:execute) @@ -156,4 +156,25 @@ RSpec.describe BulkImports::Projects::Pipelines::ProjectAttributesPipeline do pipeline.json_attributes end end + + describe '#after_run' do + it 'removes tmp dir' do + allow(FileUtils).to receive(:remove_entry).and_call_original + expect(FileUtils).to receive(:remove_entry).with(tmpdir).and_call_original + + pipeline.after_run(nil) + + expect(Dir.exist?(tmpdir)).to eq(false) + end + + context 'when dir does not exist' do + it 'does not attempt to remove tmpdir' do + FileUtils.remove_entry(tmpdir) + + expect(FileUtils).not_to receive(:remove_entry).with(tmpdir) + + pipeline.after_run(nil) + end + end + end end |