...
1apiVersion: apiextensions.k8s.io/v1 # Hack because controller-gen complains if we don't have this
2name: "[Stable] Example API"
3crd: 0000_50_stabletype-default.crd.yaml
4tests:
5 onCreate:
6 - name: Should persist stable fields
7 initial: |
8 apiVersion: example.openshift.io/v1
9 kind: StableConfigType
10 spec:
11 stableField: "Allowed"
12 immutableField: foo
13 expected: |
14 apiVersion: example.openshift.io/v1
15 kind: StableConfigType
16 spec:
17 stableField: "Allowed"
18 immutableField: foo
19 - name: Should not persist a tech preview field
20 initial: |
21 apiVersion: example.openshift.io/v1
22 kind: StableConfigType
23 spec:
24 coolNewField: "Invalid"
25 immutableField: foo
26 expected: |
27 apiVersion: example.openshift.io/v1
28 kind: StableConfigType
29 spec:
30 immutableField: foo
31 - name: With an EvolvingUnion, Should allow an empty enum value
32 initial: |
33 apiVersion: example.openshift.io/v1
34 kind: StableConfigType
35 spec:
36 evolvingUnion:
37 type: ""
38 immutableField: foo
39 expected: |
40 apiVersion: example.openshift.io/v1
41 kind: StableConfigType
42 spec:
43 evolvingUnion:
44 type: ""
45 immutableField: foo
46 - name: With an EvolvingUnion, Should allow a Stable enum value
47 initial: |
48 apiVersion: example.openshift.io/v1
49 kind: StableConfigType
50 spec:
51 evolvingUnion:
52 type: StableValue
53 immutableField: foo
54 expected: |
55 apiVersion: example.openshift.io/v1
56 kind: StableConfigType
57 spec:
58 evolvingUnion:
59 type: StableValue
60 immutableField: foo
61 - name: With an EvolvingUnion, Should not allow a TechPreview enum value
62 initial: |
63 apiVersion: example.openshift.io/v1
64 kind: StableConfigType
65 spec:
66 evolvingUnion:
67 type: TechPreviewOnlyValue
68 immutableField: foo
69 expectedError: "spec.evolvingUnion.type: Unsupported value: \"TechPreviewOnlyValue\": supported values: \"\", \"StableValue\""
70 - name: With an CEL validated Discrminated union, should allow an empty member with the empty type value
71 initial: |
72 apiVersion: example.openshift.io/v1
73 kind: StableConfigType
74 spec:
75 celUnion:
76 type: EmptyMember
77 immutableField: foo
78 expected: |
79 apiVersion: example.openshift.io/v1
80 kind: StableConfigType
81 spec:
82 celUnion:
83 type: EmptyMember
84 immutableField: foo
85 - name: With an CEL validated Discrminated union, should allow an empty member with the empty type value
86 initial: |
87 apiVersion: example.openshift.io/v1
88 kind: StableConfigType
89 spec:
90 celUnion:
91 type: EmptyMember
92 immutableField: foo
93 expected: |
94 apiVersion: example.openshift.io/v1
95 kind: StableConfigType
96 spec:
97 celUnion:
98 type: EmptyMember
99 immutableField: foo
100 - name: With an CEL validated Discrminated union, should allow a required member with the required type value
101 initial: |
102 apiVersion: example.openshift.io/v1
103 kind: StableConfigType
104 spec:
105 celUnion:
106 type: RequiredMember
107 requiredMember: foo
108 immutableField: foo
109 expected: |
110 apiVersion: example.openshift.io/v1
111 kind: StableConfigType
112 spec:
113 celUnion:
114 type: RequiredMember
115 requiredMember: foo
116 immutableField: foo
117 - name: With an CEL validated Discrminated union, should not allow omitting required member with the required type value
118 initial: |
119 apiVersion: example.openshift.io/v1
120 kind: StableConfigType
121 spec:
122 celUnion:
123 type: RequiredMember
124 immutableField: foo
125 expectedError: "Invalid value: \"object\": requiredMember is required when type is RequiredMember, and forbidden otherwise"
126 - name: With an CEL validated Discrminated union, should not allow the required member without the required type value
127 initial: |
128 apiVersion: example.openshift.io/v1
129 kind: StableConfigType
130 spec:
131 celUnion:
132 requiredMember: foo
133 immutableField: foo
134 expectedError: "Invalid value: \"object\": requiredMember is required when type is RequiredMember, and forbidden otherwise"
135 - name: With an CEL validated Discrminated union, should not allow the optional member with the required type value
136 initial: |
137 apiVersion: example.openshift.io/v1
138 kind: StableConfigType
139 spec:
140 celUnion:
141 type: RequiredMember
142 requiredMember: foo
143 optionalMember: foo
144 immutableField: foo
145 expectedError: "Invalid value: \"object\": optionalMember is forbidden when type is not OptionalMember"
146 - name: With an CEL validated Discrminated union, should allow an optional member with the optional type value
147 initial: |
148 apiVersion: example.openshift.io/v1
149 kind: StableConfigType
150 spec:
151 celUnion:
152 type: OptionalMember
153 optionalMember: foo
154 immutableField: foo
155 expected: |
156 apiVersion: example.openshift.io/v1
157 kind: StableConfigType
158 spec:
159 celUnion:
160 type: OptionalMember
161 optionalMember: foo
162 immutableField: foo
163 - name: With an CEL validated Discrminated union, should allow omitting the optional member with the optional type value
164 initial: |
165 apiVersion: example.openshift.io/v1
166 kind: StableConfigType
167 spec:
168 celUnion:
169 type: OptionalMember
170 immutableField: foo
171 expected: |
172 apiVersion: example.openshift.io/v1
173 kind: StableConfigType
174 spec:
175 celUnion:
176 type: OptionalMember
177 immutableField: foo
178 - name: With an CEL validated Discrminated union, should not allow the optional member without the optional type value
179 initial: |
180 apiVersion: example.openshift.io/v1
181 kind: StableConfigType
182 spec:
183 celUnion:
184 optionalMember: foo
185 immutableField: foo
186 expectedError: "Invalid value: \"object\": optionalMember is forbidden when type is not OptionalMember"
187 - name: With an CEL validated Discrminated union, should not allow the required member with the optional type value
188 initial: |
189 apiVersion: example.openshift.io/v1
190 kind: StableConfigType
191 spec:
192 celUnion:
193 type: OptionalMember
194 requiredMember: foo
195 immutableField: foo
196 expectedError: "Invalid value: \"object\": requiredMember is required when type is RequiredMember, and forbidden otherwise"
197 onUpdate:
198 - name: Should not allow changing an immutable field
199 initial: |
200 apiVersion: example.openshift.io/v1
201 kind: StableConfigType
202 spec:
203 immutableField: foo
204 updated: |
205 apiVersion: example.openshift.io/v1
206 kind: StableConfigType
207 spec:
208 immutableField: bar
209 expectedError: "spec.immutableField: Invalid value: \"string\": immutableField is immutable"
210 - name: Should allow setting the optional immutable field
211 initial: |
212 apiVersion: example.openshift.io/v1
213 kind: StableConfigType
214 spec:
215 immutableField: foo
216 updated: |
217 apiVersion: example.openshift.io/v1
218 kind: StableConfigType
219 spec:
220 immutableField: foo
221 optionalImmutableField: foo
222 expected: |
223 apiVersion: example.openshift.io/v1
224 kind: StableConfigType
225 spec:
226 immutableField: foo
227 optionalImmutableField: foo
228 - name: Should not allow changing the optional immutable field
229 initial: |
230 apiVersion: example.openshift.io/v1
231 kind: StableConfigType
232 spec:
233 immutableField: foo
234 optionalImmutableField: foo
235 updated: |
236 apiVersion: example.openshift.io/v1
237 kind: StableConfigType
238 spec:
239 immutableField: foo
240 optionalImmutableField: bar
241 expectedError: "spec.optionalImmutableField: Invalid value: \"string\": optionalImmutableField is immutable once set"
242 - name: Should allow setting an immutable status field
243 initial: |
244 apiVersion: example.openshift.io/v1
245 kind: StableConfigType
246 updated: |
247 apiVersion: example.openshift.io/v1
248 kind: StableConfigType
249 status:
250 immutableField: bar
251 expected: |
252 apiVersion: example.openshift.io/v1
253 kind: StableConfigType
254 status:
255 immutableField: bar
256 - name: Should not allow changing an immutable status field
257 initial: |
258 apiVersion: example.openshift.io/v1
259 kind: StableConfigType
260 status:
261 immutableField: foo
262 updated: |
263 apiVersion: example.openshift.io/v1
264 kind: StableConfigType
265 status:
266 immutableField: bar
267 expectedStatusError: "status.immutableField: Invalid value: \"string\": immutableField is immutable"
View as plain text