blob: 64f0a64074c215727af6282f1738609c7c936c0e (
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Ci::Config::Entry::Rules::Rule::Changes do
let(:factory) do
Gitlab::Config::Entry::Factory.new(described_class)
.value(config)
end
subject(:entry) { factory.create! }
before do
entry.compose!
end
describe '.new' do
context 'when using a string array' do
let(:config) { %w[app/ lib/ spec/ other/* paths/**/*.rb] }
it { is_expected.to be_valid }
end
context 'when using an integer array' do
let(:config) { [1, 2] }
it { is_expected.not_to be_valid }
it 'returns errors' do
expect(entry.errors).to include(/changes config should be an array of strings/)
end
end
context 'when using a string' do
let(:config) { 'a regular string' }
it { is_expected.not_to be_valid }
it 'reports an error about invalid policy' do
expect(entry.errors).to include(/should be an array or a hash/)
end
end
context 'when using a long array' do
let(:config) { ['app/'] * 51 }
it { is_expected.not_to be_valid }
it 'returns errors' do
expect(entry.errors).to include(/has too many entries \(maximum 50\)/)
end
end
context 'when clause is empty' do
let(:config) {}
it { is_expected.to be_valid }
end
context 'when policy strategy does not match' do
let(:config) { 'string strategy' }
it { is_expected.not_to be_valid }
it 'returns information about errors' do
expect(entry.errors)
.to include(/should be an array or a hash/)
end
end
context 'with paths' do
context 'when paths is an array of strings' do
let(:config) { { paths: %w[app/ lib/] } }
it { is_expected.to be_valid }
end
context 'when paths is not an array' do
let(:config) { { paths: 'string' } }
it { is_expected.not_to be_valid }
it 'returns information about errors' do
expect(entry.errors)
.to include(/should be an array of strings/)
end
end
context 'when paths is an array of integers' do
let(:config) { { paths: [1, 2] } }
it { is_expected.not_to be_valid }
it 'returns information about errors' do
expect(entry.errors)
.to include(/should be an array of strings/)
end
end
context 'when paths is an array of long strings' do
let(:config) { { paths: ['a'] * 51 } }
it { is_expected.not_to be_valid }
it 'returns information about errors' do
expect(entry.errors)
.to include(/has too many entries \(maximum 50\)/)
end
end
context 'when paths is nil' do
let(:config) { { paths: nil } }
it { is_expected.not_to be_valid }
it 'returns information about errors' do
expect(entry.errors)
.to include(/should be an array of strings/)
end
end
end
context 'with paths and compare_to' do
let(:config) { { paths: %w[app/ lib/], compare_to: 'branch1' } }
it { is_expected.to be_valid }
context 'when compare_to is not a string' do
let(:config) { { paths: %w[app/ lib/], compare_to: 1 } }
it { is_expected.not_to be_valid }
it 'returns information about errors' do
expect(entry.errors)
.to include(/should be a string/)
end
end
end
end
describe '#value' do
subject(:value) { entry.value }
context 'when using a string array' do
let(:config) { %w[app/ lib/ spec/ other/* paths/**/*.rb] }
it { is_expected.to eq(paths: config) }
end
context 'with paths' do
let(:config) do
{ paths: ['app/', 'lib/'] }
end
it { is_expected.to eq(config) }
end
context 'with paths and compare_to' do
let(:config) do
{ paths: ['app/', 'lib/'], compare_to: 'branch1' }
end
it { is_expected.to eq(config) }
end
end
end
|