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

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

require 'spec_helper'

RSpec.describe Gitlab::Ci::Pipeline::Chain::EvaluateWorkflowRules do
  let(:project)  { create(:project) }
  let(:user)     { create(:user) }
  let(:pipeline) { build(:ci_pipeline, project: project) }

  let(:command) do
    Gitlab::Ci::Pipeline::Chain::Command.new(project: project, current_user: user)
  end

  let(:step) { described_class.new(pipeline, command) }
  let(:ff_always_set_pipeline_failure_reason) { true }

  describe '#perform!' do
    context 'when pipeline has been skipped by workflow configuration' do
      before do
        stub_feature_flags(always_set_pipeline_failure_reason: ff_always_set_pipeline_failure_reason)

        allow(step).to receive(:workflow_rules_result)
          .and_return(
            double(pass?: false, variables: {})
          )

        step.perform!
      end

      it 'does not save the pipeline' do
        expect(pipeline).not_to be_persisted
      end

      it 'breaks the chain' do
        expect(step.break?).to be true
      end

      it 'attaches an error to the pipeline' do
        expect(pipeline.errors[:base]).to include('Pipeline filtered out by workflow rules.')
      end

      it 'saves workflow_rules_result' do
        expect(command.workflow_rules_result.variables).to eq({})
      end

      it 'sets the failure reason', :aggregate_failures do
        expect(pipeline).to be_failed
        expect(pipeline).to be_filtered_by_workflow_rules
      end

      context 'when always_set_pipeline_failure_reason is disabled' do
        let(:ff_always_set_pipeline_failure_reason) { false }

        it 'does not set the failure reason', :aggregate_failures do
          expect(pipeline).not_to be_failed
          expect(pipeline.failure_reason).to be_blank
        end
      end
    end

    context 'when pipeline has not been skipped by workflow configuration' do
      before do
        allow(step).to receive(:workflow_rules_result)
          .and_return(
            double(pass?: true, variables: { 'VAR1' => 'val2', 'VAR2' => 3 })
          )

        step.perform!
      end

      it 'continues the pipeline processing chain' do
        expect(step.break?).to be false
      end

      it 'does not skip the pipeline' do
        expect(pipeline).not_to be_persisted
        expect(pipeline).not_to be_skipped
      end

      it 'attaches no errors' do
        expect(pipeline.errors).to be_empty
      end

      it 'saves workflow_rules_result' do
        expect(command.workflow_rules_result.variables).to eq({ 'VAR1' => 'val2', 'VAR2' => 3 })
      end

      it 'does not set a failure reason' do
        expect(pipeline).not_to be_filtered_by_workflow_rules
      end
    end
  end
end