diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 11:18:50 +0000 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/lib/gitlab/import_export/importer_spec.rb | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) | |
download | gitlab-ce-8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781.tar.gz |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/lib/gitlab/import_export/importer_spec.rb')
-rw-r--r-- | spec/lib/gitlab/import_export/importer_spec.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/spec/lib/gitlab/import_export/importer_spec.rb b/spec/lib/gitlab/import_export/importer_spec.rb index 60179146416..494f7e3a00d 100644 --- a/spec/lib/gitlab/import_export/importer_spec.rb +++ b/spec/lib/gitlab/import_export/importer_spec.rb @@ -18,6 +18,7 @@ describe Gitlab::ImportExport::Importer do FileUtils.mkdir_p(shared.export_path) ImportExportUpload.create(project: project, import_file: import_file) + allow(FileUtils).to receive(:rm_rf).and_call_original end after do @@ -78,6 +79,13 @@ describe Gitlab::ImportExport::Importer do expect(project.import_export_upload.import_file&.file).to be_nil end + it 'removes tmp files' do + importer.execute + + expect(FileUtils).to have_received(:rm_rf).with(shared.base_path) + expect(Dir.exist?(shared.base_path)).to eq(false) + end + it 'sets the correct visibility_level when visibility level is a string' do project.create_or_update_import_data( data: { override_params: { visibility_level: Gitlab::VisibilityLevel::PRIVATE.to_s } } @@ -89,6 +97,49 @@ describe Gitlab::ImportExport::Importer do end end + context 'when import fails' do + let(:error_message) { 'foo' } + + shared_examples 'removes any non migrated snippet' do + specify do + create_list(:project_snippet, 2, project: project) + snippet_with_repo = create(:project_snippet, :repository, project: project) + + expect { importer.execute }.to change(Snippet, :count).by(-2).and(raise_error(Projects::ImportService::Error)) + + expect(snippet_with_repo.reload).to be_present + end + end + + context 'when there is a graceful error' do + before do + allow_next_instance_of(Gitlab::ImportExport::AvatarRestorer) do |instance| + allow(instance).to receive(:avatar_export_file).and_raise(StandardError, error_message) + end + end + + it 'raises and exception' do + expect { importer.execute }.to raise_error(Projects::ImportService::Error, error_message) + end + + it_behaves_like 'removes any non migrated snippet' + end + + context 'when an unexpected exception is raised' do + before do + allow_next_instance_of(Gitlab::ImportExport::AvatarRestorer) do |instance| + allow(instance).to receive(:restore).and_raise(StandardError, error_message) + end + end + + it 'captures it and raises the Projects::ImportService::Error exception' do + expect { importer.execute }.to raise_error(Projects::ImportService::Error, error_message) + end + + it_behaves_like 'removes any non migrated snippet' + end + end + context 'when project successfully restored' do context "with a project in a user's namespace" do let!(:existing_project) { create(:project, namespace: user.namespace) } |