blob: b5155dff6e8aef2823c1fb215887bb57c8c8dece (
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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Ci::Config::Header::Input, feature_category: :pipeline_composition do
let(:factory) do
Gitlab::Config::Entry::Factory
.new(described_class)
.value(input_hash)
.with(key: input_name)
end
let(:input_name) { 'foo' }
subject(:config) { factory.create!.tap(&:compose!) }
shared_examples 'a valid input' do
let(:expected_hash) { input_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 input' do
let(:expected_hash) { input_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 has a default value' do
let(:input_hash) { { default: 'bar' } }
it_behaves_like 'a valid input'
end
context 'when is a required input' do
let(:input_hash) { nil }
it_behaves_like 'a valid input'
end
context 'when given a valid type' do
where(:input_type) { ::Gitlab::Ci::Config::Interpolation::Inputs.input_types }
with_them do
let(:input_hash) { { type: input_type } }
it_behaves_like 'a valid input'
end
end
context 'when given an invalid type' do
let(:input_hash) { { type: 'datetime' } }
let(:expected_errors) { ['foo input type unknown value: datetime'] }
it_behaves_like 'an invalid input'
end
context 'when contains unknown keywords' do
let(:input_hash) { { test: 123 } }
let(:expected_errors) { ['foo config contains unknown keys: test'] }
it_behaves_like 'an invalid input'
end
context 'when has invalid name' do
let(:input_name) { [123] }
let(:input_hash) { {} }
let(:expected_errors) { ['123 key must be an alphanumeric string'] }
it_behaves_like 'an invalid input'
end
end
|