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

traces_rake_spec.rb « gitlab « tasks « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aaf0d7242dd50c97ff1ffa51d92ce320bdd49056 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
require 'rake_helper'

describe 'gitlab:traces rake tasks' do
  before do
    Rake.application.rake_require 'tasks/gitlab/traces'
  end

  describe 'gitlab:traces:archive' do
    shared_examples 'passes the job id to worker' do
      it do
        expect(ArchiveTraceWorker).to receive(:bulk_perform_async).with([[job.id]])

        run_rake_task('gitlab:traces:archive')
      end
    end

    shared_examples 'does not pass the job id to worker' do
      it do
        expect(ArchiveTraceWorker).not_to receive(:bulk_perform_async)

        run_rake_task('gitlab:traces:archive')
      end
    end

    context 'when trace file stored in default path' do
      let!(:job) { create(:ci_build, :success, :trace_live) }

      it_behaves_like 'passes the job id to worker'
    end

    context 'when trace is stored in database' do
      let!(:job) { create(:ci_build, :success) }

      before do
        job.update_column(:trace, 'trace in db')
      end

      it_behaves_like 'passes the job id to worker'
    end

    context 'when job has trace artifact' do
      let!(:job) { create(:ci_build, :success) }

      before do
        create(:ci_job_artifact, :trace, job: job)
      end

      it_behaves_like 'does not pass the job id to worker'
    end

    context 'when job is not finished yet' do
      let!(:build) { create(:ci_build, :running, :trace_live) }

      it_behaves_like 'does not pass the job id to worker'
    end
  end

  describe 'gitlab:traces:migrate' do
    let(:object_storage_enabled) { false }

    before do
      stub_artifacts_object_storage(enabled: object_storage_enabled)
    end

    subject { run_rake_task('gitlab:traces:migrate') }

    let!(:job_trace) { create(:ci_job_artifact, :trace, file_store: store) }

    context 'when local storage is used' do
      let(:store) { ObjectStorage::Store::LOCAL }

      context 'and job does not have file store defined' do
        let(:object_storage_enabled) { true }
        let(:store) { nil }

        it "migrates file to remote storage" do
          subject

          expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::REMOTE)
        end
      end

      context 'and remote storage is defined' do
        let(:object_storage_enabled) { true }

        it "migrates file to remote storage" do
          subject

          expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::REMOTE)
        end
      end

      context 'and remote storage is not defined' do
        it "fails to migrate to remote storage" do
          subject

          expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::LOCAL)
        end
      end
    end

    context 'when remote storage is used' do
      let(:object_storage_enabled) { true }
      let(:store) { ObjectStorage::Store::REMOTE }

      it "file stays on remote storage" do
        subject

        expect(job_trace.reload.file_store).to eq(ObjectStorage::Store::REMOTE)
      end
    end
  end
end