summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/ci/config/edge_stages_injector_spec.rb
blob: 042f9b591b62a8816b444920d3daead0a43e81e7 (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
# frozen_string_literal: true

require 'fast_spec_helper'

describe Gitlab::Ci::Config::EdgeStagesInjector do
  describe '#call' do
    subject { described_class.new(config).to_hash }

    context 'without stages' do
      let(:config) do
        {
          test: { script: 'test' }
        }
      end

      it { is_expected.to match config }
    end

    context 'with values' do
      let(:config) do
        {
          stages: %w[stage1 stage2],
          test: { script: 'test' }
        }
      end

      let(:expected_stages) do
        %w[.pre stage1 stage2 .post]
      end

      it { is_expected.to match(config.merge(stages: expected_stages)) }
    end

    context 'with bad values' do
      let(:config) do
        {
          stages: 'stage1',
          test: { script: 'test' }
        }
      end

      it { is_expected.to match(config) }
    end

    context 'with collision values' do
      let(:config) do
        {
          stages: %w[.post stage1 .pre .post stage2],
          test: { script: 'test' }
        }
      end

      let(:expected_stages) do
        %w[.pre stage1 stage2 .post]
      end

      it { is_expected.to match(config.merge(stages: expected_stages)) }
    end

    context 'with types' do
      let(:config) do
        {
          types: %w[stage1 stage2],
          test: { script: 'test' }
        }
      end

      let(:expected_config) do
        {
          types: %w[.pre stage1 stage2 .post],
          test: { script: 'test' }
        }
      end

      it { is_expected.to match expected_config }
    end

    context 'with types' do
      let(:config) do
        {
          types: %w[.post stage1 .pre .post stage2],
          test: { script: 'test' }
        }
      end

      let(:expected_config) do
        {
          types: %w[.pre stage1 stage2 .post],
          test: { script: 'test' }
        }
      end

      it { is_expected.to match expected_config }
    end
  end

  describe '.wrap_stages' do
    subject { described_class.wrap_stages(stages) }

    context 'with empty value' do
      let(:stages) {}

      it { is_expected.to eq %w[.pre .post] }
    end

    context 'with values' do
      let(:stages) { %w[s1 .pre] }

      it { is_expected.to eq %w[.pre s1 .post] }
    end
  end
end