diff options
Diffstat (limited to 'spec/lib/gitlab/import_export')
14 files changed, 181 insertions, 18 deletions
diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 5d1e3c79474..f81db1413c2 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -113,6 +113,7 @@ releases: - author - project - links +- sorted_links - milestone_releases - milestones - evidences @@ -124,6 +125,7 @@ project_members: - source - project merge_requests: +- status_check_responses - subscriptions - award_emoji - author @@ -258,6 +260,8 @@ ci_pipelines: - latest_statuses - dast_profile - dast_profiles_pipeline +- dast_site_profile +- dast_site_profiles_pipeline ci_refs: - project - ci_pipelines @@ -302,7 +306,7 @@ deploy_keys: - user - deploy_keys_projects - projects -services: +integrations: - project - service_hook - jira_tracker_data @@ -341,8 +345,9 @@ project: - external_approval_rules - taggings - base_tags -- tag_taggings - tags +- topic_taggings +- topics - chat_services - cluster - clusters @@ -350,12 +355,13 @@ project: - cluster_project - creator - cycle_analytics_stages +- value_streams - group - namespace - management_clusters - boards - last_event -- services +- integrations - campfire_service - confluence_service - datadog_service @@ -369,7 +375,6 @@ project: - packagist_service - pivotaltracker_service - prometheus_service -- hipchat_service - flowdock_service - assembla_service - asana_service @@ -569,6 +574,7 @@ project: - debian_distributions - merge_request_metrics - security_orchestration_policy_configuration +- timelogs award_emoji: - awardable - user @@ -745,3 +751,5 @@ issuable_sla: - issue push_rule: - group +bulk_import_export: + - group diff --git a/spec/lib/gitlab/import_export/attribute_configuration_spec.rb b/spec/lib/gitlab/import_export/attribute_configuration_spec.rb index 0581f07dd3f..7e17d56def0 100644 --- a/spec/lib/gitlab/import_export/attribute_configuration_spec.rb +++ b/spec/lib/gitlab/import_export/attribute_configuration_spec.rb @@ -35,8 +35,9 @@ RSpec.describe 'Import/Export attribute configuration' do <<-MSG It looks like #{relation_class}, which is exported using the project Import/Export, has new attributes: #{new_attributes.join(',')} - Please add the attribute(s) to SAFE_MODEL_ATTRIBUTES if you consider this can be exported. - Please blacklist the attribute(s) in IMPORT_EXPORT_CONFIG by adding it to its correspondent + Please add the attribute(s) to SAFE_MODEL_ATTRIBUTES if they can be exported. + + Please denylist the attribute(s) in IMPORT_EXPORT_CONFIG by adding it to its corresponding model in the +excluded_attributes+ section. SAFE_MODEL_ATTRIBUTES: #{File.expand_path(safe_attributes_file)} diff --git a/spec/lib/gitlab/import_export/base/relation_factory_spec.rb b/spec/lib/gitlab/import_export/base/relation_factory_spec.rb index 09e6e5a03bb..df33b4896a4 100644 --- a/spec/lib/gitlab/import_export/base/relation_factory_spec.rb +++ b/spec/lib/gitlab/import_export/base/relation_factory_spec.rb @@ -13,6 +13,7 @@ RSpec.describe Gitlab::ImportExport::Base::RelationFactory do subject do described_class.create(relation_sym: relation_sym, relation_hash: relation_hash, + relation_index: 1, object_builder: Gitlab::ImportExport::Project::ObjectBuilder, members_mapper: members_mapper, user: user, 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 b00a2597681..4000e303816 100644 --- a/spec/lib/gitlab/import_export/command_line_util_spec.rb +++ b/spec/lib/gitlab/import_export/command_line_util_spec.rb @@ -35,4 +35,19 @@ RSpec.describe Gitlab::ImportExport::CommandLineUtil do it 'has the right mask for uploads' do expect(file_permissions("#{path}/uploads")).to eq(0755) # originally 555 end + + describe '#gzip' do + it 'compresses specified file' do + tempfile = Tempfile.new('test', path) + filename = File.basename(tempfile.path) + + subject.gzip(dir: path, filename: filename) + end + + context 'when exception occurs' do + it 'raises an exception' do + expect { subject.gzip(dir: path, filename: 'test') }.to raise_error(Gitlab::ImportExport::Error) + end + end + end end diff --git a/spec/lib/gitlab/import_export/config_spec.rb b/spec/lib/gitlab/import_export/config_spec.rb index 40cf75779b6..7ad5d3d846c 100644 --- a/spec/lib/gitlab/import_export/config_spec.rb +++ b/spec/lib/gitlab/import_export/config_spec.rb @@ -25,7 +25,7 @@ RSpec.describe Gitlab::ImportExport::Config do expect { subject }.not_to raise_error expect(subject).to be_a(Hash) expect(subject.keys).to contain_exactly( - :tree, :excluded_attributes, :included_attributes, :methods, :preloads) + :tree, :excluded_attributes, :included_attributes, :methods, :preloads, :export_reorders) end end end diff --git a/spec/lib/gitlab/import_export/file_importer_spec.rb b/spec/lib/gitlab/import_export/file_importer_spec.rb index dc668e972cf..ed4436b7257 100644 --- a/spec/lib/gitlab/import_export/file_importer_spec.rb +++ b/spec/lib/gitlab/import_export/file_importer_spec.rb @@ -71,6 +71,22 @@ RSpec.describe Gitlab::ImportExport::FileImporter do it 'creates the file in the right subfolder' do expect(shared.export_path).to include('test/abcd') end + + context 'when the import file is remote' do + include AfterNextHelpers + + it 'downloads the file from a remote object storage' do + file_url = 'https://remote.url/file' + import_export_upload = build(:import_export_upload, remote_import_url: file_url) + project = build( :project, import_export_upload: import_export_upload) + + expect_next(described_class) + .to receive(:download) + .with(file_url, kind_of(String)) + + described_class.import(importable: project, archive_file: nil, shared: shared) + end + end end context 'error' do diff --git a/spec/lib/gitlab/import_export/group/relation_factory_spec.rb b/spec/lib/gitlab/import_export/group/relation_factory_spec.rb index 6b2f80cc80a..63286fc0719 100644 --- a/spec/lib/gitlab/import_export/group/relation_factory_spec.rb +++ b/spec/lib/gitlab/import_export/group/relation_factory_spec.rb @@ -12,6 +12,7 @@ RSpec.describe Gitlab::ImportExport::Group::RelationFactory do described_class.create( relation_sym: relation_sym, relation_hash: relation_hash, + relation_index: 1, members_mapper: members_mapper, object_builder: Gitlab::ImportExport::Group::ObjectBuilder, user: importer_user, diff --git a/spec/lib/gitlab/import_export/json/legacy_reader/file_spec.rb b/spec/lib/gitlab/import_export/json/legacy_reader/file_spec.rb index 9c7f41cbb89..e092891f236 100644 --- a/spec/lib/gitlab/import_export/json/legacy_reader/file_spec.rb +++ b/spec/lib/gitlab/import_export/json/legacy_reader/file_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -require_relative 'shared_example.rb' +require_relative 'shared_example' RSpec.describe Gitlab::ImportExport::JSON::LegacyReader::File do it_behaves_like 'import/export json legacy reader' do diff --git a/spec/lib/gitlab/import_export/json/legacy_reader/hash_spec.rb b/spec/lib/gitlab/import_export/json/legacy_reader/hash_spec.rb index d0899accf59..e47122b6151 100644 --- a/spec/lib/gitlab/import_export/json/legacy_reader/hash_spec.rb +++ b/spec/lib/gitlab/import_export/json/legacy_reader/hash_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require 'spec_helper' -require_relative 'shared_example.rb' +require_relative 'shared_example' RSpec.describe Gitlab::ImportExport::JSON::LegacyReader::Hash do it_behaves_like 'import/export json legacy reader' do 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 762687beedb..a0b2faaecfe 100644 --- a/spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb +++ b/spec/lib/gitlab/import_export/json/streaming_serializer_spec.rb @@ -30,12 +30,14 @@ RSpec.describe Gitlab::ImportExport::JSON::StreamingSerializer do let(:json_writer) { instance_double('Gitlab::ImportExport::JSON::LegacyWriter') } let(:hash) { { name: exportable.name, description: exportable.description }.stringify_keys } let(:include) { [] } + let(:custom_orderer) { nil } let(:relations_schema) do { only: [:name, :description], include: include, - preload: { issues: nil } + preload: { issues: nil }, + export_reorder: custom_orderer } end @@ -57,19 +59,63 @@ RSpec.describe Gitlab::ImportExport::JSON::StreamingSerializer do [{ issues: { include: [] } }] end + before do + create_list(:issue, 3, project: exportable, relative_position: 10000) # ascending ids, same position positive + create_list(:issue, 3, project: exportable, relative_position: -5000) # ascending ids, same position negative + create_list(:issue, 3, project: exportable, relative_position: 0) # ascending ids, duplicate positions + create_list(:issue, 3, project: exportable, relative_position: nil) # no position + create_list(:issue, 3, :with_desc_relative_position, project: exportable ) # ascending ids, descending position + end + it 'calls json_writer.write_relation_array with proper params' do expect(json_writer).to receive(:write_relation_array).with(exportable_path, :issues, array_including(issue.to_json)) subject.execute end - context 'relation ordering' do - before do - create_list(:issue, 5, project: exportable) + context 'default relation ordering' do + it 'orders exported issues by primary key(:id)' do + expected_issues = exportable.issues.reorder(:id).map(&:to_json) + + expect(json_writer).to receive(:write_relation_array).with(exportable_path, :issues, expected_issues) + + subject.execute end + end - it 'orders exported issues by primary key' do - expected_issues = exportable.issues.reorder(:id).map(&:to_json) + context 'custom relation ordering ascending' do + let(:custom_orderer) do + { + issues: { + column: :relative_position, + direction: :asc, + nulls_position: :nulls_last + } + } + end + + it 'orders exported issues by custom column(relative_position)' do + expected_issues = exportable.issues.reorder(:relative_position, :id).map(&:to_json) + + expect(json_writer).to receive(:write_relation_array).with(exportable_path, :issues, expected_issues) + + subject.execute + end + end + + context 'custom relation ordering descending' do + let(:custom_orderer) do + { + issues: { + column: :relative_position, + direction: :desc, + nulls_position: :nulls_first + } + } + 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) expect(json_writer).to receive(:write_relation_array).with(exportable_path, :issues, expected_issues) diff --git a/spec/lib/gitlab/import_export/project/relation_factory_spec.rb b/spec/lib/gitlab/import_export/project/relation_factory_spec.rb index 56ba730e893..38e700e8f9e 100644 --- a/spec/lib/gitlab/import_export/project/relation_factory_spec.rb +++ b/spec/lib/gitlab/import_export/project/relation_factory_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::ImportExport::Project::RelationFactory do +RSpec.describe Gitlab::ImportExport::Project::RelationFactory, :use_clean_rails_memory_store_caching do let(:group) { create(:group) } let(:project) { create(:project, :repository, group: group) } let(:members_mapper) { double('members_mapper').as_null_object } @@ -13,6 +13,7 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory do described_class.create( relation_sym: relation_sym, relation_hash: relation_hash, + relation_index: 1, object_builder: Gitlab::ImportExport::Project::ObjectBuilder, members_mapper: members_mapper, user: importer_user, @@ -171,6 +172,75 @@ RSpec.describe Gitlab::ImportExport::Project::RelationFactory do end end + context 'issue object' do + let(:relation_sym) { :issues } + + let(:exported_member) do + { + "id" => 111, + "access_level" => 30, + "source_id" => 1, + "source_type" => "Project", + "user_id" => 3, + "notification_level" => 3, + "created_at" => "2016-11-18T09:29:42.634Z", + "updated_at" => "2016-11-18T09:29:42.634Z", + "user" => { + "id" => admin.id, + "email" => admin.email, + "username" => admin.username + } + } + end + + let(:members_mapper) do + Gitlab::ImportExport::MembersMapper.new( + exported_members: [exported_member], + user: importer_user, + importable: project) + end + + let(:relation_hash) do + { + 'id' => 20, + 'target_branch' => "feature", + 'source_branch' => "feature_conflict", + 'project_id' => project.id, + 'author_id' => admin.id, + 'assignee_id' => admin.id, + 'updated_by_id' => admin.id, + 'title' => "Issue 1", + 'created_at' => "2016-06-14T15:02:36.568Z", + 'updated_at' => "2016-06-14T15:02:56.815Z", + 'state' => "opened", + 'description' => "Description", + "relative_position" => 25111 # just a random position + } + end + + it 'has preloaded project' do + expect(created_object.project).to equal(project) + end + + context 'computing relative position' do + context 'when max relative position in the hierarchy is not cached' do + it 'has computed new relative_position' do + expect(created_object.relative_position).to equal(1026) # 513*2 - ideal distance + end + end + + context 'when max relative position in the hierarchy is cached' do + before do + Rails.cache.write("import:#{project.model_name.plural}:#{project.id}:hierarchy_max_issues_relative_position", 10000) + end + + it 'has computed new relative_position' do + expect(created_object.relative_position).to equal(10000 + 1026) # 513*2 - ideal distance + end + end + end + end + context 'label object' do let(:relation_sym) { :labels } let(:relation_hash) do diff --git a/spec/lib/gitlab/import_export/project/sample/relation_factory_spec.rb b/spec/lib/gitlab/import_export/project/sample/relation_factory_spec.rb index 86d5f2402f8..9dde09a7602 100644 --- a/spec/lib/gitlab/import_export/project/sample/relation_factory_spec.rb +++ b/spec/lib/gitlab/import_export/project/sample/relation_factory_spec.rb @@ -17,6 +17,7 @@ RSpec.describe Gitlab::ImportExport::Project::Sample::RelationFactory do described_class.create( # rubocop:disable Rails/SaveBang relation_sym: relation_sym, relation_hash: relation_hash, + relation_index: 1, object_builder: Gitlab::ImportExport::Project::ObjectBuilder, members_mapper: members_mapper, user: importer_user, diff --git a/spec/lib/gitlab/import_export/references_configuration_spec.rb b/spec/lib/gitlab/import_export/references_configuration_spec.rb index 2934d0059ee..6320fbed975 100644 --- a/spec/lib/gitlab/import_export/references_configuration_spec.rb +++ b/spec/lib/gitlab/import_export/references_configuration_spec.rb @@ -38,8 +38,9 @@ RSpec.describe 'Import/Export Project configuration' do <<-MSG It looks like #{relation_class}, which is exported using the project Import/Export, has references: #{prohibited_keys.join(',')} - Please replace it with actual relation in IMPORT_EXPORT_CONFIG if you consider this can be exported. - Please blacklist the attribute(s) in IMPORT_EXPORT_CONFIG by adding it to its correspondent + Please replace it with actual relation in IMPORT_EXPORT_CONFIG if they can be exported. + + Please denylist the attribute(s) in IMPORT_EXPORT_CONFIG by adding it to its corresponding model in the +excluded_attributes+ section. IMPORT_EXPORT_CONFIG: #{Gitlab::ImportExport.config_file} diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml index b159d0cfc76..70ebff2a54e 100644 --- a/spec/lib/gitlab/import_export/safe_model_attributes.yml +++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml @@ -102,6 +102,7 @@ ProjectLabel: - template - description - priority +- remove_on_close Milestone: - id - title @@ -208,6 +209,7 @@ MergeRequest: - discussion_locked - allow_maintainer_to_push - merge_ref_sha +- draft MergeRequestDiff: - id - state @@ -640,6 +642,7 @@ Timelog: - time_spent - merge_request_id - user_id +- project_id - spent_at - created_at - updated_at |