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

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

require 'spec_helper'

RSpec.describe Ci::CreateDownstreamPipelineWorker do
  let_it_be(:user) { create(:user) }
  let_it_be(:project) { create(:project) }
  let_it_be(:pipeline) { create(:ci_pipeline, project: project) }

  let(:bridge) { create(:ci_bridge, user: user, pipeline: pipeline) }

  describe '#perform' do
    context 'when bridge exists' do
      let(:service) { double('pipeline creation service') }

      let(:service_result) { ServiceResponse.success(payload: instance_double(Ci::Pipeline, id: 100)) }

      it 'calls cross project pipeline creation service and logs the new pipeline id' do
        expect(Ci::CreateDownstreamPipelineService)
          .to receive(:new)
          .with(project, user)
          .and_return(service)

        expect(service)
          .to receive(:execute)
          .with(bridge)
          .and_return(service_result)

        worker = described_class.new
        worker.perform(bridge.id)

        expect(worker.logging_extras).to eq({ "extra.ci_create_downstream_pipeline_worker.new_pipeline_id" => 100 })
      end

      context 'when downstream pipeline creation errors' do
        let(:service_result) { ServiceResponse.error(message: 'Already has a downstream pipeline') }

        it 'calls cross project pipeline creation service and logs the error' do
          expect(Ci::CreateDownstreamPipelineService)
            .to receive(:new)
            .with(project, user)
            .and_return(service)

          expect(service)
            .to receive(:execute)
            .with(bridge)
            .and_return(service_result)

          worker = described_class.new
          worker.perform(bridge.id)

          expect(worker.logging_extras).to eq(
            {
              "extra.ci_create_downstream_pipeline_worker.create_error_message" => "Already has a downstream pipeline"
            }
          )
        end
      end
    end

    context 'when bridge does not exist' do
      it 'does nothing' do
        expect(Ci::CreateDownstreamPipelineService)
          .not_to receive(:new)

        described_class.new.perform(non_existing_record_id)
      end
    end
  end
end