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

relation_export_worker_spec.rb « import_export « projects « workers « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 16ee73040b1f86e741089012dc9db68a50f8bdd3 (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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Projects::ImportExport::RelationExportWorker, type: :worker, feature_category: :importers do
  let(:project_relation_export) { create(:project_relation_export) }
  let(:job_args) { [project_relation_export.id] }

  it_behaves_like 'an idempotent worker'

  describe '#perform' do
    subject(:worker) { described_class.new }

    context 'when relation export has initial status `queued`' do
      it 'exports the relation' do
        expect_next_instance_of(Projects::ImportExport::RelationExportService) do |service|
          expect(service).to receive(:execute)
        end

        worker.perform(project_relation_export.id)
      end
    end

    context 'when relation export has status `started`' do
      let(:project_relation_export) { create(:project_relation_export, :started) }

      it 'retries the export of the relation' do
        expect_next_instance_of(Projects::ImportExport::RelationExportService) do |service|
          expect(service).to receive(:execute)
        end

        worker.perform(project_relation_export.id)

        expect(project_relation_export.reload.queued?).to eq(true)
      end
    end

    context 'when relation export does not have status `queued` or `started`' do
      let(:project_relation_export) { create(:project_relation_export, :finished) }

      it 'does not export the relation' do
        expect(Projects::ImportExport::RelationExportService).not_to receive(:new)

        worker.perform(project_relation_export.id)
      end
    end
  end

  describe '.sidekiq_retries_exhausted' do
    let(:job) { { 'args' => [project_relation_export.id], 'error_message' => 'Error message' } }

    it 'sets relation export status to `failed`' do
      described_class.sidekiq_retries_exhausted_block.call(job)

      expect(project_relation_export.reload.failed?).to eq(true)
    end

    it 'logs the error message' do
      expect_next_instance_of(Gitlab::Export::Logger) do |logger|
        expect(logger).to receive(:error).with(
          hash_including(
            message: 'Project relation export failed',
            export_error: 'Error message'
          )
        )
      end

      described_class.sidekiq_retries_exhausted_block.call(job)
    end
  end
end