Welcome to mirror list, hosted at ThFree Co, Russian Federation.

file_export_service_spec.rb « bulk_imports « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 94efceff6c61c2b2862fb50f480b453b19b45b55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe BulkImports::FileExportService do
  let_it_be(:project) { create(:project) }
  let_it_be(:export_path) { Dir.mktmpdir }
  let_it_be(:relation) { BulkImports::FileTransfer::BaseConfig::UPLOADS_RELATION }

  subject(:service) { described_class.new(project, export_path, relation) }

  describe '#execute' do
    it 'executes export service and archives exported data' do
      expect_next_instance_of(BulkImports::UploadsExportService) do |service|
        expect(service).to receive(:execute)
      end

      expect(subject).to receive(:tar_cf).with(archive: File.join(export_path, 'uploads.tar'), dir: export_path)

      subject.execute
    end

    context 'when relation is lfs objects' do
      let_it_be(:relation) { BulkImports::FileTransfer::ProjectConfig::LFS_OBJECTS_RELATION }

      it 'executes lfs objects export service' do
        expect_next_instance_of(BulkImports::LfsObjectsExportService) do |service|
          expect(service).to receive(:execute)
        end

        expect(subject).to receive(:tar_cf).with(archive: File.join(export_path, 'lfs_objects.tar'), dir: export_path)

        subject.execute
      end
    end

    context 'when unsupported relation is passed' do
      it 'raises an error' do
        service = described_class.new(project, export_path, 'unsupported')

        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
      expect(subject.exported_filename).to eq('uploads.tar')
    end
  end
end