Commit 616e66ce authored by Peter Leitzen's avatar Peter Leitzen

Merge branch 'group-import-with-json-or-ndjson' into 'master'

Group import with json or ndjson

See merge request gitlab-org/gitlab!30055
parents 150e4d45 fccdf43f
......@@ -36,7 +36,7 @@ module Groups
def restorer
@restorer ||=
if ::Feature.enabled?(:group_import_export_ndjson, @group&.parent)
if ndjson?
Gitlab::ImportExport::Group::TreeRestorer.new(
user: @current_user,
shared: @shared,
......@@ -52,6 +52,11 @@ module Groups
end
end
def ndjson?
::Feature.enabled?(:group_import_export_ndjson, @group&.parent) &&
File.exist?(File.join(@shared.export_path, 'tree/groups/_all.ndjson'))
end
def remove_import_file
upload = @group.import_export_upload
......
......@@ -3,7 +3,48 @@
require 'spec_helper'
describe Groups::ImportExport::ImportService do
describe '#execute with TreeRestorer' do
context 'with group_import_export_ndjson feature flag disabled' do
let(:user) { create(:admin) }
let(:group) { create(:group) }
let(:import_logger) { instance_double(Gitlab::Import::Logger) }
subject(:service) { described_class.new(group: group, user: user) }
before do
stub_feature_flags(group_import_export_ndjson: false)
ImportExportUpload.create(group: group, import_file: import_file)
allow(Gitlab::Import::Logger).to receive(:build).and_return(import_logger)
allow(import_logger).to receive(:error)
allow(import_logger).to receive(:info)
end
context 'with a json file' do
let(:import_file) { fixture_file_upload('spec/fixtures/legacy_group_export.tar.gz') }
it 'uses LegacyTreeRestorer to import the file' do
expect(Gitlab::ImportExport::Group::LegacyTreeRestorer).to receive(:new).and_call_original
service.execute
end
end
context 'with a ndjson file' do
let(:import_file) { fixture_file_upload('spec/fixtures/group_export.tar.gz') }
it 'fails to import' do
expect { service.execute }.to raise_error(Gitlab::ImportExport::Error, 'Incorrect JSON format')
end
end
end
context 'with group_import_export_ndjson feature flag enabled' do
before do
stub_feature_flags(group_import_export_ndjson: true)
end
context 'when importing a ndjson export' do
let(:user) { create(:admin) }
let(:group) { create(:group) }
let(:service) { described_class.new(group: group, user: user) }
......@@ -14,8 +55,6 @@ describe Groups::ImportExport::ImportService do
subject { service.execute }
before do
stub_feature_flags(group_import_export_ndjson: true)
ImportExportUpload.create(group: group, import_file: import_file)
allow(Gitlab::Import::Logger).to receive(:build).and_return(import_logger)
......@@ -105,7 +144,7 @@ describe Groups::ImportExport::ImportService do
end
end
describe '#execute with LegacyTreeRestorer' do
context 'when importing a json export' do
let(:user) { create(:admin) }
let(:group) { create(:group) }
let(:service) { described_class.new(group: group, user: user) }
......@@ -116,8 +155,6 @@ describe Groups::ImportExport::ImportService do
subject { service.execute }
before do
stub_feature_flags(group_import_export_ndjson: false)
ImportExportUpload.create(group: group, import_file: import_file)
allow(Gitlab::Import::Logger).to receive(:build).and_return(import_logger)
......@@ -206,4 +243,5 @@ describe Groups::ImportExport::ImportService do
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment