-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconditions_test.yaml
193 lines (192 loc) · 5.48 KB
/
conditions_test.yaml
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
schemas_subsets:
# v1alpha1 is a subset of the features from v1beta1
# For this reason, any test that uses v1alpha1 will also be executed for v1beta1
v1alpha1:
- v1beta1
# Each suite stresses a specific operator or set of operators used to specify conditions
# Each test specifies the schema used to parse the condition. Notice that the same test
# will be executed by all the schemas that are a superset of the one specified in the test.
# A test is composed by different cases. Each case defines the actual condition to be tested,
# some context (optional) and the expected result.
test_suites:
- name: AND
tests:
- schemas: [v1alpha1]
cases:
- condition:
and:
- const: true
- const: true
expected_result: true
- condition:
and:
- const: true
- const: false
expected_result: false
- condition:
and:
- const: false
expected_result: false
- condition:
and: []
expected_result: true
- name: OR
tests:
- schemas: [v1alpha1]
cases:
- condition:
or:
- const: false
- const: false
expected_result: false
- condition:
or:
- const: true
- const: false
expected_result: true
- condition:
or:
- const: true
expected_result: true
- name: NOT
tests:
- schemas: [v1alpha1]
cases:
- condition:
not:
const: true
expected_result: false
- condition:
not:
const: false
expected_result: true
- name: EQUAL
tests:
- schemas: [v1alpha1]
cases:
- condition:
equal:
- const: 1
expected_result: true
- condition:
equal:
- const: 1
- const: 2
expected_result: false
- condition:
equal:
- const: 2
- const: 2
expected_result: true
- name: SUM
tests:
- schemas: [v1alpha1]
cases:
- condition:
sum:
- const: 1
- const: 2
- const: 3
expected_result: 6
- condition:
sum:
- const: 2
expected_result: 2
- name: GET_VALUE
tests:
- schemas: [v1alpha1]
cases:
# Retrieve value from last context
- condition:
getValue: .name
context:
- metadata:
name: foo
spec: {}
- name: bar
expected_result: bar
# Retrieve value from first context
- condition:
getValue: $.metadata.name
context:
- metadata:
name: foo
spec: {}
- name: bar
expected_result: foo
- name: FOR_EACH
tests:
- schemas: [v1alpha1]
cases:
# Iterate over a constant list of elements and sum 10 to each
- condition:
forEach:
elements:
const: [1, 2]
op:
sum:
- const: 10
- getValue: "."
expected_result: [11, 12]
# Iterate over a list defined in the yaml file and sum 1 to each
- condition:
forEach:
elements:
getValue: .containers
op:
sum:
- const: 1
- getValue: .maxCPU
context:
- containers:
- maxCPU: 1
- maxCPU: 2
expected_result: [2, 3]
- name: CONTAIN
tests:
- schemas: [v1alpha1]
cases:
- condition:
contain:
elements:
getValue: .containers
value:
const: { maxCPU: 2 }
context:
- containers:
- maxCPU: 1
- maxCPU: 2
expected_result: true
- condition:
contain:
elements:
getValue: .containers
value:
const: { maxCPU: 4 }
context:
- containers:
- maxCPU: 1
- maxCPU: 2
expected_result: false
- name: RAW_STR_EXPR
tests:
- schemas: [v1beta1]
cases:
- condition: "2 * (3 + 4 / 2) - 1"
expected_result: 9
- condition: "2*(3+4/2)-1"
expected_result: 9
- condition: "8/4/2"
expected_result: 1
- condition: "1 == 1 && 1 != 0 && 0 <= 0 && 0 < 1 && 1 > 0 && 1 >= 1 && true"
expected_result: true
- condition: "1 != 1 || 1 == 0 || 0 < 0 || 0 >= 1 || 1 <= 0 || 1 < 1 || false"
expected_result: false
- condition: '"foo" == "foo" && "foo" != "bar"'
expected_result: true
- condition: ".containers.0.maxCPU + 1 == .containers.1.maxCPU"
context:
- containers:
- maxCPU: 1
- maxCPU: 2
expected_result: true