2019-12-10 07:53:40 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# This spec is a lightweight version of:
|
2020-03-17 09:09:20 +00:00
|
|
|
# * project/tree_restorer_spec.rb
|
2019-12-10 07:53:40 +00:00
|
|
|
#
|
|
|
|
# In depth testing is being done in the above specs.
|
|
|
|
# This spec tests that restore project works
|
|
|
|
# but does not have 100% relation coverage.
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Gitlab::ImportExport::RelationTreeRestorer do
|
|
|
|
include ImportExport::CommonUtil
|
|
|
|
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:shared) { Gitlab::ImportExport::Shared.new(importable) }
|
2020-04-08 03:09:31 +00:00
|
|
|
let(:attributes) { relation_reader.consume_attributes(importable_name) }
|
2019-12-10 07:53:40 +00:00
|
|
|
|
2020-03-26 18:08:03 +00:00
|
|
|
let(:members_mapper) do
|
|
|
|
Gitlab::ImportExport::MembersMapper.new(exported_members: {}, user: user, importable: importable)
|
2019-12-10 07:53:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
let(:relation_tree_restorer) do
|
|
|
|
described_class.new(
|
2020-03-26 18:08:03 +00:00
|
|
|
user: user,
|
|
|
|
shared: shared,
|
|
|
|
relation_reader: relation_reader,
|
|
|
|
object_builder: object_builder,
|
|
|
|
members_mapper: members_mapper,
|
|
|
|
relation_factory: relation_factory,
|
|
|
|
reader: reader,
|
|
|
|
importable: importable,
|
2020-04-08 03:09:31 +00:00
|
|
|
importable_path: importable_path,
|
2020-03-26 18:08:03 +00:00
|
|
|
importable_attributes: attributes
|
2019-12-10 07:53:40 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { relation_tree_restorer.restore }
|
|
|
|
|
2020-03-17 09:09:20 +00:00
|
|
|
shared_examples 'import project successfully' do
|
2019-12-10 07:53:40 +00:00
|
|
|
it 'restores project tree' do
|
|
|
|
expect(subject).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'imported project' do
|
|
|
|
let(:project) { Project.find_by_path('project') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
|
|
|
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)
|
|
|
|
expect(project.project_feature).not_to be_nil
|
|
|
|
expect(project.custom_attributes.count).to eq(2)
|
|
|
|
expect(project.project_badges.count).to eq(2)
|
|
|
|
expect(project.snippets.count).to eq(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-03-17 09:09:20 +00:00
|
|
|
|
2020-03-20 15:09:17 +00:00
|
|
|
shared_examples 'logging of relations creation' do
|
|
|
|
context 'when log_import_export_relation_creation feature flag is enabled' do
|
|
|
|
before do
|
2020-05-13 09:08:37 +00:00
|
|
|
stub_feature_flags(log_import_export_relation_creation: group)
|
2020-03-20 15:09:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'logs top-level relation creation' do
|
|
|
|
expect(relation_tree_restorer.shared.logger)
|
|
|
|
.to receive(:info)
|
|
|
|
.with(hash_including(message: '[Project/Group Import] Created new object relation'))
|
|
|
|
.at_least(:once)
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when log_import_export_relation_creation feature flag is disabled' do
|
|
|
|
before do
|
2020-05-13 09:08:37 +00:00
|
|
|
stub_feature_flags(log_import_export_relation_creation: false)
|
2020-03-20 15:09:17 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not log top-level relation creation' do
|
|
|
|
expect(relation_tree_restorer.shared.logger)
|
|
|
|
.to receive(:info)
|
|
|
|
.with(hash_including(message: '[Project/Group Import] Created new object relation'))
|
|
|
|
.never
|
|
|
|
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-17 09:09:20 +00:00
|
|
|
context 'when restoring a project' do
|
|
|
|
let(:importable) { create(:project, :builds_enabled, :issues_disabled, name: 'project', path: 'project') }
|
2020-04-08 03:09:31 +00:00
|
|
|
let(:importable_name) { 'project' }
|
|
|
|
let(:importable_path) { 'project' }
|
2020-03-17 09:09:20 +00:00
|
|
|
let(:object_builder) { Gitlab::ImportExport::Project::ObjectBuilder }
|
|
|
|
let(:relation_factory) { Gitlab::ImportExport::Project::RelationFactory }
|
|
|
|
let(:reader) { Gitlab::ImportExport::Reader.new(shared: shared) }
|
|
|
|
|
|
|
|
context 'using legacy reader' do
|
2020-04-08 03:09:31 +00:00
|
|
|
let(:path) { 'spec/fixtures/lib/gitlab/import_export/complex/project.json' }
|
2020-03-26 18:08:03 +00:00
|
|
|
let(:relation_reader) do
|
|
|
|
Gitlab::ImportExport::JSON::LegacyReader::File.new(
|
|
|
|
path,
|
2020-04-08 03:09:31 +00:00
|
|
|
relation_names: reader.project_relation_names,
|
|
|
|
allowed_path: 'project'
|
2020-03-26 18:08:03 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2020-04-08 03:09:31 +00:00
|
|
|
let(:attributes) { relation_reader.consume_attributes('project') }
|
2020-03-17 09:09:20 +00:00
|
|
|
|
|
|
|
it_behaves_like 'import project successfully'
|
2020-03-20 15:09:17 +00:00
|
|
|
|
|
|
|
context 'logging of relations creation' do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:importable) { create(:project, :builds_enabled, :issues_disabled, name: 'project', path: 'project', group: group) }
|
|
|
|
|
|
|
|
include_examples 'logging of relations creation'
|
|
|
|
end
|
2020-04-08 03:09:31 +00:00
|
|
|
|
|
|
|
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
|
2020-03-20 15:09:17 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when restoring a group' do
|
|
|
|
let(:path) { 'spec/fixtures/lib/gitlab/import_export/group_exports/no_children/group.json' }
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:importable) { create(:group, parent: group) }
|
2020-04-08 03:09:31 +00:00
|
|
|
let(:importable_name) { nil }
|
|
|
|
let(:importable_path) { nil }
|
2020-03-20 15:09:17 +00:00
|
|
|
let(:object_builder) { Gitlab::ImportExport::Group::ObjectBuilder }
|
|
|
|
let(:relation_factory) { Gitlab::ImportExport::Group::RelationFactory }
|
2020-04-08 03:09:31 +00:00
|
|
|
let(:relation_reader) do
|
|
|
|
Gitlab::ImportExport::JSON::LegacyReader::File.new(
|
|
|
|
path,
|
|
|
|
relation_names: reader.group_relation_names)
|
|
|
|
end
|
|
|
|
|
2020-03-20 15:09:17 +00:00
|
|
|
let(:reader) do
|
|
|
|
Gitlab::ImportExport::Reader.new(
|
|
|
|
shared: shared,
|
2020-04-21 15:21:10 +00:00
|
|
|
config: Gitlab::ImportExport::Config.new(config: Gitlab::ImportExport.legacy_group_config_file).to_h
|
2020-03-20 15:09:17 +00:00
|
|
|
)
|
2020-03-17 09:09:20 +00:00
|
|
|
end
|
2020-03-20 15:09:17 +00:00
|
|
|
|
2020-04-08 03:09:31 +00:00
|
|
|
it 'restores group tree' do
|
|
|
|
expect(subject).to eq(true)
|
|
|
|
end
|
|
|
|
|
2020-03-20 15:09:17 +00:00
|
|
|
include_examples 'logging of relations creation'
|
2020-03-17 09:09:20 +00:00
|
|
|
end
|
2019-12-10 07:53:40 +00:00
|
|
|
end
|