summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/import_export
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/import_export')
-rw-r--r--spec/lib/gitlab/import_export/all_models.yml8
-rw-r--r--spec/lib/gitlab/import_export/attributes_permitter_spec.rb52
-rw-r--r--spec/lib/gitlab/import_export/command_line_util_spec.rb34
-rw-r--r--spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb19
-rw-r--r--spec/lib/gitlab/import_export/merge_request_parser_spec.rb36
-rw-r--r--spec/lib/gitlab/import_export/relation_tree_restorer_spec.rb40
-rw-r--r--spec/lib/gitlab/import_export/snippet_repo_restorer_spec.rb3
7 files changed, 109 insertions, 83 deletions
diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml
index 614aa55c3c5..10f0e687077 100644
--- a/spec/lib/gitlab/import_export/all_models.yml
+++ b/spec/lib/gitlab/import_export/all_models.yml
@@ -59,6 +59,7 @@ issues:
- requirement
- incident_management_issuable_escalation_status
- pending_escalations
+- customer_relations_contacts
work_item_type:
- issues
events:
@@ -272,6 +273,8 @@ ci_pipelines:
- dast_profiles_pipeline
- dast_site_profile
- dast_site_profiles_pipeline
+- package_build_infos
+- package_file_build_infos
ci_refs:
- project
- ci_pipelines
@@ -322,7 +325,6 @@ integrations:
- jira_tracker_data
- zentao_tracker_data
- issue_tracker_data
-- open_project_tracker_data
hooks:
- project
- web_hook_logs
@@ -354,10 +356,7 @@ container_repositories:
- name
project:
- external_status_checks
-- taggings
- base_tags
-- topic_taggings
-- topics_acts_as_taggable
- project_topics
- topics
- chat_services
@@ -593,6 +592,7 @@ project:
- pending_builds
- security_scans
- ci_feature_usages
+- bulk_import_exports
award_emoji:
- awardable
- user
diff --git a/spec/lib/gitlab/import_export/attributes_permitter_spec.rb b/spec/lib/gitlab/import_export/attributes_permitter_spec.rb
index 36a831a785c..2b974f8985d 100644
--- a/spec/lib/gitlab/import_export/attributes_permitter_spec.rb
+++ b/spec/lib/gitlab/import_export/attributes_permitter_spec.rb
@@ -83,14 +83,22 @@ RSpec.describe Gitlab::ImportExport::AttributesPermitter do
where(:relation_name, :permitted_attributes_defined) do
:user | false
:author | false
- :ci_cd_settings | false
- :issuable_sla | false
- :push_rule | false
+ :ci_cd_settings | true
:metrics_setting | true
:project_badges | true
:pipeline_schedules | true
:error_tracking_setting | true
:auto_devops | true
+ :boards | true
+ :custom_attributes | true
+ :labels | true
+ :protected_branches | true
+ :protected_tags | true
+ :create_access_levels | true
+ :merge_access_levels | true
+ :push_access_levels | true
+ :releases | true
+ :links | true
end
with_them do
@@ -99,47 +107,11 @@ RSpec.describe Gitlab::ImportExport::AttributesPermitter do
end
describe 'included_attributes for Project' do
- let(:prohibited_attributes) { %i[remote_url my_attributes my_ids token my_id test] }
-
subject { described_class.new }
Gitlab::ImportExport::Config.new.to_h[:included_attributes].each do |relation_sym, permitted_attributes|
context "for #{relation_sym}" do
- let(:import_export_config) { Gitlab::ImportExport::Config.new.to_h }
- let(:project_relation_factory) { Gitlab::ImportExport::Project::RelationFactory }
-
- let(:relation_hash) { (permitted_attributes + prohibited_attributes).map(&:to_s).zip([]).to_h }
- let(:relation_name) { project_relation_factory.overrides[relation_sym]&.to_sym || relation_sym }
- let(:relation_class) { project_relation_factory.relation_class(relation_name) }
- let(:excluded_keys) { import_export_config.dig(:excluded_keys, relation_sym) || [] }
-
- let(:cleaned_hash) do
- Gitlab::ImportExport::AttributeCleaner.new(
- relation_hash: relation_hash,
- relation_class: relation_class,
- excluded_keys: excluded_keys
- ).clean
- end
-
- let(:permitted_hash) { subject.permit(relation_sym, relation_hash) }
-
- if described_class.new.permitted_attributes_defined?(relation_sym)
- it 'contains only attributes that are defined as permitted in the import/export config' do
- expect(permitted_hash.keys).to contain_exactly(*permitted_attributes.map(&:to_s))
- end
-
- it 'does not contain attributes that would be cleaned with AttributeCleaner' do
- expect(cleaned_hash.keys).to include(*permitted_hash.keys)
- end
-
- it 'does not contain prohibited attributes that are not related to given relation' do
- expect(permitted_hash.keys).not_to include(*prohibited_attributes.map(&:to_s))
- end
- else
- it 'is disabled' do
- expect(subject).not_to be_permitted_attributes_defined(relation_sym)
- end
- end
+ it_behaves_like 'a permitted attribute', relation_sym, permitted_attributes
end
end
end
diff --git a/spec/lib/gitlab/import_export/command_line_util_spec.rb b/spec/lib/gitlab/import_export/command_line_util_spec.rb
index 39a10f87083..59c4e1083ae 100644
--- a/spec/lib/gitlab/import_export/command_line_util_spec.rb
+++ b/spec/lib/gitlab/import_export/command_line_util_spec.rb
@@ -8,6 +8,7 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil do
let(:path) { "#{Dir.tmpdir}/symlink_test" }
let(:archive) { 'spec/fixtures/symlink_export.tar.gz' }
let(:shared) { Gitlab::ImportExport::Shared.new(nil) }
+ let(:tmpdir) { Dir.mktmpdir }
subject do
Class.new do
@@ -26,6 +27,7 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil do
after do
FileUtils.rm_rf(path)
+ FileUtils.remove_entry(tmpdir)
end
it 'has the right mask for project.json' do
@@ -55,7 +57,6 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil do
describe '#gunzip' do
it 'decompresses specified file' do
- tmpdir = Dir.mktmpdir
filename = 'labels.ndjson.gz'
gz_filepath = "spec/fixtures/bulk_imports/gz/#{filename}"
FileUtils.copy_file(gz_filepath, File.join(tmpdir, filename))
@@ -63,8 +64,6 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil do
subject.gunzip(dir: tmpdir, filename: filename)
expect(File.exist?(File.join(tmpdir, 'labels.ndjson'))).to eq(true)
-
- FileUtils.remove_entry(tmpdir)
end
context 'when exception occurs' do
@@ -73,4 +72,33 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil do
end
end
end
+
+ describe '#tar_cf' do
+ let(:archive_dir) { Dir.mktmpdir }
+
+ after do
+ FileUtils.remove_entry(archive_dir)
+ end
+
+ it 'archives a folder without compression' do
+ archive_file = File.join(archive_dir, 'archive.tar')
+
+ result = subject.tar_cf(archive: archive_file, dir: tmpdir)
+
+ expect(result).to eq(true)
+ expect(File.exist?(archive_file)).to eq(true)
+ end
+
+ context 'when something goes wrong' do
+ it 'raises an error' do
+ expect(Gitlab::Popen).to receive(:popen).and_return(['Error', 1])
+
+ klass = Class.new do
+ include Gitlab::ImportExport::CommandLineUtil
+ end.new
+
+ expect { klass.tar_cf(archive: 'test', dir: 'test') }.to raise_error(Gitlab::ImportExport::Error, 'System call failed')
+ end
+ end
+ end
end
diff --git a/spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb b/spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb
index 9e30564b437..d69d775fffb 100644
--- a/spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb
+++ b/spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb
@@ -115,7 +115,7 @@ RSpec.describe Gitlab::ImportExport::Json::StreamingSerializer do
end
it 'orders exported issues by custom column(relative_position)' do
- expected_issues = exportable.issues.order_relative_position_desc.order(id: :desc).map(&:to_json)
+ expected_issues = exportable.issues.reorder(::Gitlab::Database.nulls_first_order('relative_position', 'DESC')).order(id: :desc).map(&:to_json)
expect(json_writer).to receive(:write_relation_array).with(exportable_path, :issues, expected_issues)
@@ -163,21 +163,10 @@ RSpec.describe Gitlab::ImportExport::Json::StreamingSerializer do
stub_feature_flags(load_balancing_for_export_workers: true)
end
- context 'when enabled', :db_load_balancing do
- it 'reads from replica' do
- expect(Gitlab::Database::LoadBalancing::Session.current).to receive(:use_replicas_for_read_queries).and_call_original
+ it 'reads from replica' do
+ expect(Gitlab::Database::LoadBalancing::Session.current).to receive(:use_replicas_for_read_queries).and_call_original
- subject.execute
- end
- end
-
- context 'when disabled' do
- it 'reads from primary' do
- allow(Gitlab::Database::LoadBalancing).to receive(:enable?).and_return(false)
- expect(Gitlab::Database::LoadBalancing::Session.current).not_to receive(:use_replicas_for_read_queries)
-
- subject.execute
- end
+ subject.execute
end
end
diff --git a/spec/lib/gitlab/import_export/merge_request_parser_spec.rb b/spec/lib/gitlab/import_export/merge_request_parser_spec.rb
index c558c12f581..550cefea805 100644
--- a/spec/lib/gitlab/import_export/merge_request_parser_spec.rb
+++ b/spec/lib/gitlab/import_export/merge_request_parser_spec.rb
@@ -13,9 +13,11 @@ RSpec.describe Gitlab::ImportExport::MergeRequestParser do
create(:merge_request, source_project: forked_project, target_project: project)
end
+ let(:diff_head_sha) { SecureRandom.hex(20) }
+
let(:parsed_merge_request) do
described_class.new(project,
- 'abcd',
+ diff_head_sha,
merge_request,
merge_request.as_json).parse!
end
@@ -34,14 +36,34 @@ RSpec.describe Gitlab::ImportExport::MergeRequestParser do
expect(project.repository.branch_exists?(parsed_merge_request.target_branch)).to be true
end
- it 'parses a MR that has no source branch' do
- allow_next_instance_of(described_class) do |instance|
- allow(instance).to receive(:branch_exists?).and_call_original
- allow(instance).to receive(:branch_exists?).with(merge_request.source_branch).and_return(false)
- allow(instance).to receive(:fork_merge_request?).and_return(true)
+ # Source and target branch are only created when: fork_merge_request
+ context 'fork merge request' do
+ before do
+ allow_next_instance_of(described_class) do |instance|
+ allow(instance).to receive(:fork_merge_request?).and_return(true)
+ end
+ end
+
+ it 'parses a MR that has no source branch' do
+ allow_next_instance_of(described_class) do |instance|
+ allow(instance).to receive(:branch_exists?).and_call_original
+ allow(instance).to receive(:branch_exists?).with(merge_request.source_branch).and_return(false)
+ end
+
+ expect(parsed_merge_request).to eq(merge_request)
end
- expect(parsed_merge_request).to eq(merge_request)
+ it 'parses a MR that is closed' do
+ merge_request.update!(state: :closed, source_branch: 'new_branch')
+
+ expect(project.repository.branch_exists?(parsed_merge_request.source_branch)).to be false
+ end
+
+ it 'parses a MR that is merged' do
+ merge_request.update!(state: :merged, source_branch: 'new_branch')
+
+ expect(project.repository.branch_exists?(parsed_merge_request.source_branch)).to be false
+ end
end
context 'when the merge request has diffs' do
diff --git a/spec/lib/gitlab/import_export/relation_tree_restorer_spec.rb b/spec/lib/gitlab/import_export/relation_tree_restorer_spec.rb
index 9325cdac9ed..5e4075c2b59 100644
--- a/spec/lib/gitlab/import_export/relation_tree_restorer_spec.rb
+++ b/spec/lib/gitlab/import_export/relation_tree_restorer_spec.rb
@@ -30,18 +30,12 @@ RSpec.describe Gitlab::ImportExport::RelationTreeRestorer do
subject { relation_tree_restorer.restore }
shared_examples 'import project successfully' do
- it 'restores project tree' do
- expect(subject).to eq(true)
- end
-
describe 'imported project' do
- let(:project) { Project.find_by_path('project') }
+ it 'has the project attributes and relations', :aggregate_failures do
+ expect(subject).to eq(true)
- before do
- subject
- end
+ project = Project.find_by_path('project')
- it 'has the project attributes and relations' do
expect(project.description).to eq('Nisi et repellendus ut enim quo accusamus vel magnam.')
expect(project.labels.count).to eq(3)
expect(project.boards.count).to eq(1)
@@ -86,7 +80,10 @@ RSpec.describe Gitlab::ImportExport::RelationTreeRestorer do
end
context 'when restoring a project' do
- let(:importable) { create(:project, :builds_enabled, :issues_disabled, name: 'project', path: 'project') }
+ let_it_be(:importable, reload: true) do
+ create(:project, :builds_enabled, :issues_disabled, name: 'project', path: 'project')
+ end
+
let(:importable_name) { 'project' }
let(:importable_path) { 'project' }
let(:object_builder) { Gitlab::ImportExport::Project::ObjectBuilder }
@@ -108,8 +105,10 @@ RSpec.describe Gitlab::ImportExport::RelationTreeRestorer do
it_behaves_like 'import project successfully'
context 'logging of relations creation' do
- let(:group) { create(:group) }
- let(:importable) { create(:project, :builds_enabled, :issues_disabled, name: 'project', path: 'project', group: group) }
+ let_it_be(:group) { create(:group) }
+ let_it_be(:importable) do
+ create(:project, :builds_enabled, :issues_disabled, name: 'project', path: 'project', group: group)
+ end
include_examples 'logging of relations creation'
end
@@ -120,6 +119,18 @@ RSpec.describe Gitlab::ImportExport::RelationTreeRestorer do
let(:relation_reader) { Gitlab::ImportExport::Json::NdjsonReader.new(path) }
it_behaves_like 'import project successfully'
+
+ context 'when inside a group' do
+ let_it_be(:group) do
+ create(:group, :disabled_and_unoverridable)
+ end
+
+ before do
+ importable.update!(shared_runners_enabled: false, group: group)
+ end
+
+ it_behaves_like 'import project successfully'
+ end
end
context 'with invalid relations' do
@@ -143,9 +154,10 @@ RSpec.describe Gitlab::ImportExport::RelationTreeRestorer do
end
context 'when restoring a group' do
+ let_it_be(:group) { create(:group) }
+ let_it_be(:importable) { create(:group, parent: group) }
+
let(:path) { 'spec/fixtures/lib/gitlab/import_export/group_exports/no_children/group.json' }
- let(:group) { create(:group) }
- let(:importable) { create(:group, parent: group) }
let(:importable_name) { nil }
let(:importable_path) { nil }
let(:object_builder) { Gitlab::ImportExport::Group::ObjectBuilder }
diff --git a/spec/lib/gitlab/import_export/snippet_repo_restorer_spec.rb b/spec/lib/gitlab/import_export/snippet_repo_restorer_spec.rb
index c1661cf02b6..7d719b6028f 100644
--- a/spec/lib/gitlab/import_export/snippet_repo_restorer_spec.rb
+++ b/spec/lib/gitlab/import_export/snippet_repo_restorer_spec.rb
@@ -29,6 +29,9 @@ RSpec.describe Gitlab::ImportExport::SnippetRepoRestorer do
expect(restorer.restore).to be_truthy
end.to change { SnippetRepository.count }.by(1)
+ snippet.repository.expire_method_caches(%i(exists?))
+ expect(snippet.repository_exists?).to be_truthy
+
blob = snippet.repository.blob_at(snippet.default_branch, snippet.file_name)
expect(blob).not_to be_nil
expect(blob.data).to eq(snippet.content)