summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/import_export/project/export_task_spec.rb
blob: cf11a1df33ca1db22c80cfd8ed4185e9d2788004 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# frozen_string_literal: true

require 'rake_helper'

describe Gitlab::ImportExport::Project::ExportTask do
  let(:username) { 'root' }
  let(:namespace_path) { username }
  let!(:user) { create(:user, username: username) }
  let(:measurement_enabled) { false }
  let(:file_path) { 'spec/fixtures/gitlab/import_export/test_project_export.tar.gz' }
  let(:project) { create(:project, creator: user, namespace: user.namespace) }
  let(:project_name) { project.name }

  let(:task_params) do
    {
      username: username,
      namespace_path: namespace_path,
      project_path: project_name,
      file_path: file_path,
      measurement_enabled: measurement_enabled
    }
  end

  subject { described_class.new(task_params).export }

  context 'when project is found' do
    let(:project) { create(:project, creator: user, namespace: user.namespace) }

    around do |example|
      example.run
    ensure
      File.delete(file_path)
    end

    it 'performs project export successfully' do
      expect { subject }.to output(/Done!/).to_stdout

      expect(subject).to eq(true)

      expect(File).to exist(file_path)
    end

    it_behaves_like 'measurable'
  end

  context 'when project is not found' do
    let(:project_name) { 'invalid project name' }

    it 'logs an error' do
      expect { subject }.to output(/Project with path: #{project_name} was not found. Please provide correct project path/).to_stdout
    end

    it 'returns false' do
      expect(subject).to eq(false)
    end
  end

  context 'when file path is invalid' do
    let(:file_path) { '/invalid_file_path/test_project_export.tar.gz' }

    it 'logs an error' do
      expect { subject }.to output(/Invalid file path: #{file_path}. Please provide correct file path/ ).to_stdout
    end

    it 'returns false' do
      expect(subject).to eq(false)
    end
  end
end