2021-10-13 15:12:51 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe BulkImports::FileExportService do
|
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
|
|
|
|
describe '#execute' do
|
2022-05-23 15:08:42 +00:00
|
|
|
it 'executes export service and archives exported data for each file relation' do
|
|
|
|
relations = {
|
|
|
|
'uploads' => BulkImports::UploadsExportService,
|
|
|
|
'lfs_objects' => BulkImports::LfsObjectsExportService,
|
|
|
|
'repository' => BulkImports::RepositoryBundleExportService,
|
|
|
|
'design' => BulkImports::RepositoryBundleExportService
|
|
|
|
}
|
2021-12-23 18:14:10 +00:00
|
|
|
|
2022-05-23 15:08:42 +00:00
|
|
|
relations.each do |relation, klass|
|
|
|
|
Dir.mktmpdir do |export_path|
|
|
|
|
service = described_class.new(project, export_path, relation)
|
2021-12-23 18:14:10 +00:00
|
|
|
|
2022-05-23 15:08:42 +00:00
|
|
|
expect_next_instance_of(klass) do |service|
|
|
|
|
expect(service).to receive(:execute)
|
|
|
|
end
|
2021-12-23 18:14:10 +00:00
|
|
|
|
2022-05-23 15:08:42 +00:00
|
|
|
expect(service).to receive(:tar_cf).with(archive: File.join(export_path, "#{relation}.tar"), dir: export_path)
|
2022-05-20 06:08:54 +00:00
|
|
|
|
2022-05-23 15:08:42 +00:00
|
|
|
service.execute
|
2022-05-20 06:08:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-10-13 15:12:51 +00:00
|
|
|
context 'when unsupported relation is passed' do
|
|
|
|
it 'raises an error' do
|
2022-05-23 15:08:42 +00:00
|
|
|
service = described_class.new(project, nil, 'unsupported')
|
2021-10-13 15:12:51 +00:00
|
|
|
|
|
|
|
expect { service.execute }.to raise_error(BulkImports::Error, 'Unsupported relation export type')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#exported_filename' do
|
|
|
|
it 'returns filename of the exported file' do
|
2022-05-23 15:08:42 +00:00
|
|
|
service = described_class.new(project, nil, 'uploads')
|
|
|
|
|
|
|
|
expect(service.exported_filename).to eq('uploads.tar')
|
2021-10-13 15:12:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|