Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/bulk_imports')
-rw-r--r--spec/models/bulk_imports/export_status_spec.rb77
-rw-r--r--spec/models/bulk_imports/export_upload_spec.rb2
-rw-r--r--spec/models/bulk_imports/file_transfer/group_config_spec.rb18
-rw-r--r--spec/models/bulk_imports/file_transfer/project_config_spec.rb18
4 files changed, 108 insertions, 7 deletions
diff --git a/spec/models/bulk_imports/export_status_spec.rb b/spec/models/bulk_imports/export_status_spec.rb
new file mode 100644
index 00000000000..48f32a2092a
--- /dev/null
+++ b/spec/models/bulk_imports/export_status_spec.rb
@@ -0,0 +1,77 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe BulkImports::ExportStatus do
+ let_it_be(:relation) { 'labels' }
+ let_it_be(:import) { create(:bulk_import) }
+ let_it_be(:config) { create(:bulk_import_configuration, bulk_import: import) }
+ let_it_be(:entity) { create(:bulk_import_entity, bulk_import: import, source_full_path: 'foo') }
+ let_it_be(:tracker) { create(:bulk_import_tracker, entity: entity) }
+
+ let(:response_double) do
+ double(parsed_response: [{ 'relation' => 'labels', 'status' => status, 'error' => 'error!' }])
+ end
+
+ subject { described_class.new(tracker, relation) }
+
+ before do
+ allow_next_instance_of(BulkImports::Clients::HTTP) do |client|
+ allow(client).to receive(:get).and_return(response_double)
+ end
+ end
+
+ describe '#started?' do
+ context 'when export status is started' do
+ let(:status) { BulkImports::Export::STARTED }
+
+ it 'returns true' do
+ expect(subject.started?).to eq(true)
+ end
+ end
+
+ context 'when export status is not started' do
+ let(:status) { BulkImports::Export::FAILED }
+
+ it 'returns false' do
+ expect(subject.started?).to eq(false)
+ end
+ end
+ end
+
+ describe '#failed' do
+ context 'when export status is failed' do
+ let(:status) { BulkImports::Export::FAILED }
+
+ it 'returns true' do
+ expect(subject.failed?).to eq(true)
+ end
+ end
+
+ context 'when export status is not failed' do
+ let(:status) { BulkImports::Export::STARTED }
+
+ it 'returns false' do
+ expect(subject.failed?).to eq(false)
+ end
+ end
+ end
+
+ describe '#error' do
+ let(:status) { BulkImports::Export::FAILED }
+
+ it 'returns error message' do
+ expect(subject.error).to eq('error!')
+ end
+
+ context 'when something goes wrong during export status fetch' do
+ it 'returns exception class as error' do
+ allow_next_instance_of(BulkImports::Clients::HTTP) do |client|
+ allow(client).to receive(:get).and_raise(StandardError, 'Error!')
+ end
+
+ expect(subject.error).to eq('Error!')
+ end
+ end
+ end
+end
diff --git a/spec/models/bulk_imports/export_upload_spec.rb b/spec/models/bulk_imports/export_upload_spec.rb
index 641fa4a1b6c..d9ae41af0db 100644
--- a/spec/models/bulk_imports/export_upload_spec.rb
+++ b/spec/models/bulk_imports/export_upload_spec.rb
@@ -13,7 +13,7 @@ RSpec.describe BulkImports::ExportUpload do
method = 'export_file'
filename = 'labels.ndjson.gz'
- subject.public_send("#{method}=", fixture_file_upload("spec/fixtures/bulk_imports/#{filename}"))
+ subject.public_send("#{method}=", fixture_file_upload("spec/fixtures/bulk_imports/gz/#{filename}"))
subject.save!
url = "/uploads/-/system/bulk_imports/export_upload/export_file/#{subject.id}/#{filename}"
diff --git a/spec/models/bulk_imports/file_transfer/group_config_spec.rb b/spec/models/bulk_imports/file_transfer/group_config_spec.rb
index 21da71de3c7..4611a00b0cc 100644
--- a/spec/models/bulk_imports/file_transfer/group_config_spec.rb
+++ b/spec/models/bulk_imports/file_transfer/group_config_spec.rb
@@ -12,8 +12,8 @@ RSpec.describe BulkImports::FileTransfer::GroupConfig do
subject { described_class.new(exportable) }
- describe '#exportable_tree' do
- it 'returns exportable tree' do
+ describe '#portable_tree' do
+ it 'returns portable tree' do
expect_next_instance_of(::Gitlab::ImportExport::AttributesFinder) do |finder|
expect(finder).to receive(:find_root).with(:group).and_call_original
end
@@ -30,9 +30,21 @@ RSpec.describe BulkImports::FileTransfer::GroupConfig do
end
end
- describe '#exportable_relations' do
+ describe '#portable_relations' do
it 'returns a list of top level exportable relations' do
expect(subject.portable_relations).to include('milestones', 'badges', 'boards', 'labels')
end
end
+
+ describe '#top_relation_tree' do
+ it 'returns relation tree of a top level relation' do
+ expect(subject.top_relation_tree('labels')).to eq('priorities' => {})
+ end
+ end
+
+ describe '#relation_excluded_keys' do
+ it 'returns excluded keys for relation' do
+ expect(subject.relation_excluded_keys('group')).to include('owner_id')
+ end
+ end
end
diff --git a/spec/models/bulk_imports/file_transfer/project_config_spec.rb b/spec/models/bulk_imports/file_transfer/project_config_spec.rb
index 021f96ac2a3..2995556a58d 100644
--- a/spec/models/bulk_imports/file_transfer/project_config_spec.rb
+++ b/spec/models/bulk_imports/file_transfer/project_config_spec.rb
@@ -12,8 +12,8 @@ RSpec.describe BulkImports::FileTransfer::ProjectConfig do
subject { described_class.new(exportable) }
- describe '#exportable_tree' do
- it 'returns exportable tree' do
+ describe 'portable_tree' do
+ it 'returns portable tree' do
expect_next_instance_of(::Gitlab::ImportExport::AttributesFinder) do |finder|
expect(finder).to receive(:find_root).with(:project).and_call_original
end
@@ -30,9 +30,21 @@ RSpec.describe BulkImports::FileTransfer::ProjectConfig do
end
end
- describe '#exportable_relations' do
+ describe '#portable_relations' do
it 'returns a list of top level exportable relations' do
expect(subject.portable_relations).to include('issues', 'labels', 'milestones', 'merge_requests')
end
end
+
+ describe '#top_relation_tree' do
+ it 'returns relation tree of a top level relation' do
+ expect(subject.top_relation_tree('labels')).to eq('priorities' => {})
+ end
+ end
+
+ describe '#relation_excluded_keys' do
+ it 'returns excluded keys for relation' do
+ expect(subject.relation_excluded_keys('project')).to include('creator_id')
+ end
+ end
end