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

root_spec.rb « header « config « ci « gitlab « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 55f77137619fc583c2b9858ec63b9fb6868638ea (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Gitlab::Ci::Config::Header::Root, feature_category: :pipeline_composition do
  let(:factory) { Gitlab::Config::Entry::Factory.new(described_class).value(header_hash) }

  subject(:config) { factory.create!.tap(&:compose!) }

  shared_examples 'a valid header' do
    let(:expected_hash) { header_hash }

    it 'passes validations' do
      expect(config).to be_valid
      expect(config.errors).to be_empty
    end

    it 'returns the value' do
      expect(config.value).to eq(expected_hash)
    end
  end

  shared_examples 'an invalid header' do
    let(:expected_hash) { header_hash }

    it 'fails validations' do
      expect(config).not_to be_valid
      expect(config.errors).to eq(expected_errors)
    end

    it 'returns the value' do
      expect(config.value).to eq(expected_hash)
    end
  end

  context 'when header contains default and required values for inputs' do
    let(:header_hash) do
      {
        spec: {
          inputs: {
            test: {},
            foo: {
              default: 'bar'
            }
          }
        }
      }
    end

    it_behaves_like 'a valid header'
  end

  context 'when header contains minimal data' do
    let(:header_hash) do
      {
        spec: {
          inputs: nil
        }
      }
    end

    it_behaves_like 'a valid header' do
      let(:expected_hash) { { spec: {} } }
    end
  end

  context 'when header contains required inputs' do
    let(:header_hash) do
      {
        spec: {
          inputs: { foo: nil }
        }
      }
    end

    it_behaves_like 'a valid header' do
      let(:expected_hash) do
        {
          spec: {
            inputs: { foo: {} }
          }
        }
      end
    end
  end

  context 'when header contains unknown keywords' do
    let(:header_hash) { { test: 123 } }
    let(:expected_errors) { ['root config contains unknown keys: test'] }

    it_behaves_like 'an invalid header'
  end

  context 'when header input entry has an unknown key' do
    let(:header_hash) do
      {
        spec: {
          inputs: {
            foo: {
              bad: 'value'
            }
          }
        }
      }
    end

    let(:expected_errors) { ['spec:inputs:foo config contains unknown keys: bad'] }

    it_behaves_like 'an invalid header'
  end

  describe '#inputs_value' do
    let(:header_hash) do
      {
        spec: {
          inputs: {
            foo: nil,
            bar: {
              default: 'baz'
            }
          }
        }
      }
    end

    it 'returns the inputs' do
      expect(config.inputs_value).to eq({
        foo: {},
        bar: { default: 'baz' }
      })
    end
  end
end