summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/import_export/saver_spec.rb
blob: 02f1a4b81aa80af52f7d859a1bd1a6a812a308a4 (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
require 'spec_helper'
require 'fileutils'

describe Gitlab::ImportExport::Saver do
  let!(:project) { create(:project, :public, name: 'project') }
  let(:export_path) { "#{Dir.tmpdir}/project_tree_saver_spec" }
  let(:shared) { project.import_export_shared }
  subject { described_class.new(project: project, shared: shared) }

  before do
    allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)

    FileUtils.mkdir_p(shared.export_path)
    FileUtils.touch("#{shared.export_path}/tmp.bundle")
  end

  after do
    FileUtils.rm_rf(export_path)
  end

  context 'local archive' do
    it 'saves the repo to disk' do
      stub_feature_flags(import_export_object_storage: false)

      subject.save

      expect(shared.errors).to be_empty
      expect(Dir.empty?(shared.archive_path)).to be false
    end
  end

  context 'object storage' do
    it 'saves the repo using object storage' do
      stub_feature_flags(import_export_object_storage: true)
      stub_uploads_object_storage(ImportExportUploader)

      subject.save

      expect(ImportExportUpload.find_by(project: project).export_file.url)
        .to match(%r[\/uploads\/-\/system\/import_export_upload\/export_file.*])
    end
  end
end