blob: 5e9dee02190d2030dbe7e3ba40b45b4f869a30ea (
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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Ci::Config::Yaml::Result, feature_category: :pipeline_composition do
it 'raises an error when reading a header when there is none' do
result = described_class.new(config: { b: 2 })
expect { result.header }.to raise_error(ArgumentError)
end
it 'stores an error / exception when initialized with it' do
result = described_class.new(error: ArgumentError.new('abc'))
expect(result).not_to be_valid
expect(result.error).to be_a ArgumentError
end
it 'does not have a header when config is a single hash' do
result = described_class.new(config: { a: 1, b: 2 })
expect(result).not_to have_header
end
describe '#inputs' do
it 'returns the value of the spec inputs' do
result = described_class.new(config: [{ spec: { inputs: { website: nil } } }, { b: 2 }])
expect(result).to have_header
expect(result.inputs).to eq({ website: nil })
end
end
describe '#interpolated?' do
it 'defaults to false' do
expect(described_class.new).not_to be_interpolated
end
it 'returns the value passed to the initializer' do
expect(described_class.new(interpolated: true)).to be_interpolated
end
end
context 'when config is an array of hashes' do
context 'when first document matches the header schema' do
it 'has a header' do
result = described_class.new(config: [{ spec: { inputs: {} } }, { b: 2 }])
expect(result).to have_header
expect(result.header).to eq({ spec: { inputs: {} } })
expect(result.content).to eq({ b: 2 })
end
end
context 'when first document does not match the header schema' do
it 'does not have header' do
result = described_class.new(config: [{ a: 1 }, { b: 2 }])
expect(result).not_to have_header
expect(result.content).to eq({ a: 1 })
end
end
end
context 'when the first document is undefined' do
it 'does not have header' do
result = described_class.new(config: [nil, { a: 1 }])
expect(result).not_to have_header
expect(result.content).to be_empty
end
end
end
|