diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /spec/lib/gitlab/import_export | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'spec/lib/gitlab/import_export')
9 files changed, 135 insertions, 77 deletions
diff --git a/spec/lib/gitlab/import_export/all_models.yml b/spec/lib/gitlab/import_export/all_models.yml index 38fe2781331..fba32ae0673 100644 --- a/spec/lib/gitlab/import_export/all_models.yml +++ b/spec/lib/gitlab/import_export/all_models.yml @@ -28,6 +28,7 @@ issues: - events - merge_requests_closing_issues - metrics +- metric_images - timelogs - issuable_severity - issuable_sla @@ -85,6 +86,7 @@ label: - issues - merge_requests - priorities +- epic_board_labels milestone: - group - project @@ -105,6 +107,7 @@ snippets: - user_mentions - snippet_repository - statistics +- repository_storage_moves releases: - author - project @@ -349,6 +352,7 @@ project: - services - campfire_service - confluence_service +- datadog_service - discord_service - drone_ci_service - emails_on_push_service @@ -540,6 +544,7 @@ project: - daily_build_group_report_results - jira_imports - compliance_framework_setting +- compliance_management_frameworks - metrics_users_starred_dashboards - alert_management_alerts - repository_storage_moves @@ -548,10 +553,13 @@ project: - build_report_results - vulnerability_statistic - vulnerability_historical_statistics +- vulnerability_remediations - product_analytics_events - pipeline_artifacts - terraform_states - alert_management_http_integrations +- exported_protected_branches +- incident_management_oncall_schedules award_emoji: - awardable - user @@ -639,6 +647,7 @@ boards: - lists - destroyable_lists - milestone +- iteration - board_labels - board_assignee - assignee @@ -648,6 +657,7 @@ boards: lists: - user - milestone +- iteration - board - label - list_user_preferences diff --git a/spec/lib/gitlab/import_export/group/tree_restorer_spec.rb b/spec/lib/gitlab/import_export/group/tree_restorer_spec.rb index 2eb983cc050..2794acb8980 100644 --- a/spec/lib/gitlab/import_export/group/tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/group/tree_restorer_spec.rb @@ -75,12 +75,31 @@ RSpec.describe Gitlab::ImportExport::Group::TreeRestorer do before do setup_import_export_config('group_exports/child_with_no_parent') + end + + it 'captures import failures when a child group does not have a valid parent_id' do + group_tree_restorer.restore - expect(group_tree_restorer.restore).to be_falsey + expect(group.import_failures.first.exception_message).to eq('Parent group not found') end + end + + context 'when child group creation fails' do + let(:user) { create(:user) } + let(:group) { create(:group) } + let(:shared) { Gitlab::ImportExport::Shared.new(group) } + let(:group_tree_restorer) { described_class.new(user: user, shared: shared, group: group) } + + before do + setup_import_export_config('group_exports/child_short_name') + end + + it 'captures import failure' do + exception_message = 'Validation failed: Group URL is too short (minimum is 2 characters)' + + group_tree_restorer.restore - it 'fails when a child group does not have a valid parent_id' do - expect(shared.errors).to include('Parent group not found') + expect(group.import_failures.first.exception_message).to eq(exception_message) end end diff --git a/spec/lib/gitlab/import_export/importer_spec.rb b/spec/lib/gitlab/import_export/importer_spec.rb index 0db038785d3..75db3167ebc 100644 --- a/spec/lib/gitlab/import_export/importer_spec.rb +++ b/spec/lib/gitlab/import_export/importer_spec.rb @@ -48,7 +48,6 @@ RSpec.describe Gitlab::ImportExport::Importer do [ Gitlab::ImportExport::AvatarRestorer, Gitlab::ImportExport::RepoRestorer, - Gitlab::ImportExport::WikiRestorer, Gitlab::ImportExport::UploadsRestorer, Gitlab::ImportExport::LfsRestorer, Gitlab::ImportExport::StatisticsRestorer, @@ -65,6 +64,20 @@ RSpec.describe Gitlab::ImportExport::Importer do end end + it 'calls RepoRestorer with project and wiki' do + wiki_repo_path = File.join(shared.export_path, Gitlab::ImportExport.wiki_repo_bundle_filename) + repo_path = File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename) + restorer = double(Gitlab::ImportExport::RepoRestorer) + + expect(Gitlab::ImportExport::RepoRestorer).to receive(:new).with(path_to_bundle: repo_path, shared: shared, project: project).and_return(restorer) + expect(Gitlab::ImportExport::RepoRestorer).to receive(:new).with(path_to_bundle: wiki_repo_path, shared: shared, project: ProjectWiki.new(project)).and_return(restorer) + expect(Gitlab::ImportExport::RepoRestorer).to receive(:new).and_call_original + + expect(restorer).to receive(:restore).and_return(true).twice + + importer.execute + end + context 'with sample_data_template' do it 'initializes the Sample::TreeRestorer' do project.create_or_update_import_data(data: { sample_data: true }) diff --git a/spec/lib/gitlab/import_export/json/ndjson_writer_spec.rb b/spec/lib/gitlab/import_export/json/ndjson_writer_spec.rb index 0af74dee604..2a5e802bdc5 100644 --- a/spec/lib/gitlab/import_export/json/ndjson_writer_spec.rb +++ b/spec/lib/gitlab/import_export/json/ndjson_writer_spec.rb @@ -25,7 +25,7 @@ RSpec.describe Gitlab::ImportExport::JSON::NdjsonWriter do describe "#write_relation" do context "when single relation is serialized" do - it "appends json in correct file " do + it "appends json in correct file" do relation = "relation" value = { "key" => "value_1", "key_1" => "value_1" } subject.write_relation(exportable_path, relation, value) diff --git a/spec/lib/gitlab/import_export/project/tree_restorer_spec.rb b/spec/lib/gitlab/import_export/project/tree_restorer_spec.rb index fd3b71deb37..e2bf87bf29f 100644 --- a/spec/lib/gitlab/import_export/project/tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project/tree_restorer_spec.rb @@ -674,10 +674,12 @@ RSpec.describe Gitlab::ImportExport::Project::TreeRestorer do end it 'does not allow setting params that are excluded from import_export settings' do - project.create_import_data(data: { override_params: { lfs_enabled: true } }) + original_value = project.lfs_enabled? + + project.create_import_data(data: { override_params: { lfs_enabled: !original_value } }) expect(restored_project_json).to eq(true) - expect(project.lfs_enabled).to be_falsey + expect(project.lfs_enabled).to eq(original_value) end it 'overrides project feature access levels' 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 bd9ac6d6697..d3c14b1f8fe 100644 --- a/spec/lib/gitlab/import_export/relation_tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/relation_tree_restorer_spec.rb @@ -113,12 +113,31 @@ RSpec.describe Gitlab::ImportExport::RelationTreeRestorer do include_examples 'logging of relations creation' end + end + + context 'using ndjson reader' do + let(:path) { 'spec/fixtures/lib/gitlab/import_export/complex/tree' } + let(:relation_reader) { Gitlab::ImportExport::JSON::NdjsonReader.new(path) } + + it_behaves_like 'import project successfully' + end - context 'using ndjson reader' do - let(:path) { 'spec/fixtures/lib/gitlab/import_export/complex/tree' } - let(:relation_reader) { Gitlab::ImportExport::JSON::NdjsonReader.new(path) } + context 'with invalid relations' do + let(:path) { 'spec/fixtures/lib/gitlab/import_export/project_with_invalid_relations/tree' } + let(:relation_reader) { Gitlab::ImportExport::JSON::NdjsonReader.new(path) } - it_behaves_like 'import project successfully' + it 'logs the invalid relation and its errors' do + expect(relation_tree_restorer.shared.logger) + .to receive(:warn) + .with( + error_messages: "Title can't be blank. Title is invalid", + message: '[Project/Group Import] Invalid object relation built', + relation_class: 'ProjectLabel', + relation_index: 0, + relation_key: 'labels' + ).once + + relation_tree_restorer.restore end end end diff --git a/spec/lib/gitlab/import_export/repo_restorer_spec.rb b/spec/lib/gitlab/import_export/repo_restorer_spec.rb index b32ae60fbcc..a6b917457c2 100644 --- a/spec/lib/gitlab/import_export/repo_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/repo_restorer_spec.rb @@ -5,35 +5,42 @@ require 'spec_helper' RSpec.describe Gitlab::ImportExport::RepoRestorer do include GitHelpers + let_it_be(:project_with_repo) do + create(:project, :repository, :wiki_repo, name: 'test-repo-restorer', path: 'test-repo-restorer').tap do |p| + p.wiki.create_page('page', 'foobar', :markdown, 'created page') + end + end + + let!(:project) { create(:project) } + + let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" } + let(:shared) { project.import_export_shared } + + before do + allow(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path) + + bundler.save + end + + after do + FileUtils.rm_rf(export_path) + end + describe 'bundle a project Git repo' do - let(:user) { create(:user) } - let!(:project_with_repo) { create(:project, :repository, name: 'test-repo-restorer', path: 'test-repo-restorer') } - let!(:project) { create(:project) } - let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" } - let(:shared) { project.import_export_shared } let(:bundler) { Gitlab::ImportExport::RepoSaver.new(project: project_with_repo, shared: shared) } let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename) } subject { described_class.new(path_to_bundle: bundle_path, shared: shared, project: project) } - before do - allow_next_instance_of(Gitlab::ImportExport) do |instance| - allow(instance).to receive(:storage_path).and_return(export_path) - end - - bundler.save - end - after do - FileUtils.rm_rf(export_path) - Gitlab::GitalyClient::StorageSettings.allow_disk_access do - FileUtils.rm_rf(project_with_repo.repository.path_to_repo) - FileUtils.rm_rf(project.repository.path_to_repo) - end + Gitlab::Shell.new.remove_repository(project.repository_storage, project.disk_path) end it 'restores the repo successfully' do + expect(project.repository.exists?).to be false expect(subject.restore).to be_truthy + + expect(project.repository.empty?).to be false end context 'when the repository already exists' do @@ -53,4 +60,35 @@ RSpec.describe Gitlab::ImportExport::RepoRestorer do end end end + + describe 'restore a wiki Git repo' do + let(:bundler) { Gitlab::ImportExport::WikiRepoSaver.new(project: project_with_repo, shared: shared) } + let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.wiki_repo_bundle_filename) } + + subject { described_class.new(path_to_bundle: bundle_path, shared: shared, project: ProjectWiki.new(project)) } + + after do + Gitlab::Shell.new.remove_repository(project.wiki.repository_storage, project.wiki.disk_path) + end + + it 'restores the wiki repo successfully' do + expect(project.wiki_repository_exists?).to be false + + subject.restore + project.wiki.repository.expire_status_cache + + expect(project.wiki_repository_exists?).to be true + end + + describe 'no wiki in the bundle' do + let!(:project_without_wiki) { create(:project) } + + let(:bundler) { Gitlab::ImportExport::WikiRepoSaver.new(project: project_without_wiki, shared: shared) } + + it 'does not creates an empty wiki' do + expect(subject.restore).to be true + expect(project.wiki_repository_exists?).to be false + end + end + end end diff --git a/spec/lib/gitlab/import_export/safe_model_attributes.yml b/spec/lib/gitlab/import_export/safe_model_attributes.yml index b33462b4096..a93ee051ccf 100644 --- a/spec/lib/gitlab/import_export/safe_model_attributes.yml +++ b/spec/lib/gitlab/import_export/safe_model_attributes.yml @@ -26,7 +26,7 @@ Issue: - weight - time_estimate - relative_position -- service_desk_reply_to +- external_author - last_edited_at - last_edited_by_id - discussion_locked @@ -219,6 +219,7 @@ MergeRequestDiff: - start_commit_sha - commits_count - files_count +- sorted MergeRequestDiffCommit: - merge_request_diff_id - relative_order @@ -577,6 +578,8 @@ ProjectFeature: - pages_access_level - metrics_dashboard_access_level - requirements_access_level +- analytics_access_level +- operations_access_level - created_at - updated_at ProtectedBranch::MergeAccessLevel: @@ -742,6 +745,7 @@ Board: - updated_at - group_id - milestone_id +- iteration_id - weight - name - hide_backlog_list diff --git a/spec/lib/gitlab/import_export/wiki_restorer_spec.rb b/spec/lib/gitlab/import_export/wiki_restorer_spec.rb deleted file mode 100644 index 6c80c410d07..00000000000 --- a/spec/lib/gitlab/import_export/wiki_restorer_spec.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::ImportExport::WikiRestorer do - describe 'restore a wiki Git repo' do - let!(:project_with_wiki) { create(:project, :wiki_repo) } - let!(:project_without_wiki) { create(:project) } - let!(:project) { create(:project) } - let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" } - let(:shared) { project.import_export_shared } - let(:bundler) { Gitlab::ImportExport::WikiRepoSaver.new(project: project_with_wiki, shared: shared) } - let(:bundle_path) { File.join(shared.export_path, Gitlab::ImportExport.project_bundle_filename) } - let(:restorer) do - described_class.new(path_to_bundle: bundle_path, - shared: shared, - project: project.wiki, - wiki_enabled: true) - end - - before do - allow(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path) - - bundler.save - end - - after do - FileUtils.rm_rf(export_path) - Gitlab::Shell.new.remove_repository(project_with_wiki.wiki.repository_storage, project_with_wiki.wiki.disk_path) - Gitlab::Shell.new.remove_repository(project.wiki.repository_storage, project.wiki.disk_path) - end - - it 'restores the wiki repo successfully' do - expect(restorer.restore).to be true - end - - describe "no wiki in the bundle" do - let(:bundler) { Gitlab::ImportExport::WikiRepoSaver.new(project: project_without_wiki, shared: shared) } - - it 'creates an empty wiki' do - expect(restorer.restore).to be true - - expect(project.wiki_repository_exists?).to be true - end - end - end -end |