@@ -127,15 +127,25 @@ var _ = Describe("Basic and OLM tests", func() {
127
127
Describe ("OLM Tests" , func () {
128
128
129
129
Describe ("Test Status and Spec Descriptors" , func () {
130
- var (
131
- cr unstructured.Unstructured
132
- csv operatorsv1alpha1.ClusterServiceVersion
133
- )
134
-
135
- csv = operatorsv1alpha1.ClusterServiceVersion {
130
+ csv := operatorsv1alpha1.ClusterServiceVersion {
136
131
Spec : operatorsv1alpha1.ClusterServiceVersionSpec {
137
132
CustomResourceDefinitions : operatorsv1alpha1.CustomResourceDefinitions {
138
133
Owned : []operatorsv1alpha1.CRDDescription {
134
+ operatorsv1alpha1.CRDDescription {
135
+ Name : "Test" ,
136
+ Version : "v2" ,
137
+ Kind : "TestKind" ,
138
+ StatusDescriptors : []operatorsv1alpha1.StatusDescriptor {
139
+ operatorsv1alpha1.StatusDescriptor {
140
+ Path : "newStatus" ,
141
+ },
142
+ },
143
+ SpecDescriptors : []operatorsv1alpha1.SpecDescriptor {
144
+ operatorsv1alpha1.SpecDescriptor {
145
+ Path : "newSpec" ,
146
+ },
147
+ },
148
+ },
139
149
operatorsv1alpha1.CRDDescription {
140
150
Name : "Test" ,
141
151
Version : "v1" ,
@@ -156,147 +166,156 @@ var _ = Describe("Basic and OLM tests", func() {
156
166
},
157
167
}
158
168
159
- It ("should pass when csv with owned cr and required fields is present" , func () {
160
- cr = unstructured.Unstructured {
161
- Object : map [string ]interface {}{
162
- "status" : map [string ]interface {}{
163
- "status" : "val" ,
164
- },
165
- "spec" : map [string ]interface {}{
166
- "spec" : "val" ,
167
- },
168
- },
169
+ It ("should pass when CR Object Descriptor is nil" , func () {
170
+ cr := unstructured.Unstructured {
171
+ Object : nil ,
169
172
}
170
173
cr .SetGroupVersionKind (schema.GroupVersionKind {
171
- Kind : "TestKind" ,
172
- Group : "test.example.com" ,
174
+ Kind : "TestKind" ,
175
+ Group : "test.example.com" ,
176
+ Version : "v1" ,
173
177
})
174
178
175
179
result = checkOwnedCSVStatusDescriptor (cr , & csv , result )
176
180
Expect (result .State ).To (Equal (scapiv1alpha3 .PassState ))
177
181
})
178
182
179
- It ("should return warning when no spec status are defined for CRD " , func () {
180
- cr = unstructured.Unstructured {
183
+ It ("should pass when status descriptor field is present in CR " , func () {
184
+ cr : = unstructured.Unstructured {
181
185
Object : map [string ]interface {}{
186
+ "status" : map [string ]interface {}{
187
+ "status" : "val" ,
188
+ },
182
189
"spec" : map [string ]interface {}{
183
190
"spec" : "val" ,
184
191
},
185
192
},
186
193
}
187
194
cr .SetGroupVersionKind (schema.GroupVersionKind {
188
- Kind : "TestKind" ,
189
- Group : "test.example.com" ,
195
+ Kind : "TestKind" ,
196
+ Group : "test.example.com" ,
197
+ Version : "v1" ,
190
198
})
191
199
192
200
result = checkOwnedCSVStatusDescriptor (cr , & csv , result )
193
- Expect (result .Suggestions ).To (HaveLen (1 ))
194
201
Expect (result .State ).To (Equal (scapiv1alpha3 .PassState ))
195
202
})
196
203
197
- It ("should pass when CR Object Descriptor is nil " , func () {
204
+ It ("should pass when required spec descriptor field is present in CR " , func () {
198
205
cr := unstructured.Unstructured {
199
- Object : nil ,
206
+ Object : map [string ]interface {}{
207
+ "status" : map [string ]interface {}{
208
+ "status" : "val" ,
209
+ },
210
+ "spec" : map [string ]interface {}{
211
+ "spec" : "val" ,
212
+ },
213
+ },
200
214
}
201
215
cr .SetGroupVersionKind (schema.GroupVersionKind {
202
- Kind : "TestKind" ,
203
- Group : "test.example.com" ,
216
+ Kind : "TestKind" ,
217
+ Group : "test.example.com" ,
218
+ Version : "v1" ,
204
219
})
205
220
206
- result = checkOwnedCSVStatusDescriptor (cr , & csv , result )
221
+ result = checkOwnedCSVSpecDescriptors (cr , & csv , result )
207
222
Expect (result .State ).To (Equal (scapiv1alpha3 .PassState ))
208
223
})
209
224
210
- It ("should fail when CR Object Descriptor is nil and CRD with given GVK cannot be found " , func () {
225
+ It ("should pass with warning when no status descriptor field is present in CR " , func () {
211
226
cr := unstructured.Unstructured {
212
- Object : nil ,
227
+ Object : map [string ]interface {}{
228
+ "spec" : map [string ]interface {}{
229
+ "spec" : "val" ,
230
+ },
231
+ },
213
232
}
214
233
cr .SetGroupVersionKind (schema.GroupVersionKind {
215
- Kind : "TestKindNotPresent" ,
216
- Group : "testnotpresent.example.com" ,
234
+ Kind : "TestKind" ,
235
+ Group : "test.example.com" ,
236
+ Version : "v1" ,
217
237
})
218
238
219
239
result = checkOwnedCSVStatusDescriptor (cr , & csv , result )
220
- Expect (result .State ).To (Equal (scapiv1alpha3 .FailState ))
240
+ Expect (result .Suggestions ).To (HaveLen (1 ))
241
+ Expect (result .State ).To (Equal (scapiv1alpha3 .PassState ))
221
242
})
222
243
223
- It ("should fail when owned CRD for CR does not have GVK set " , func () {
244
+ It ("should fail CRD with given GVK cannot be found " , func () {
224
245
cr := unstructured.Unstructured {
225
246
Object : map [string ]interface {}{
226
247
"status" : map [string ]interface {}{
227
248
"status" : "val" ,
228
249
},
250
+ "spec" : map [string ]interface {}{
251
+ "spec" : "val" ,
252
+ },
229
253
},
230
254
}
255
+ cr .SetGroupVersionKind (schema.GroupVersionKind {
256
+ Kind : "TestKindNotPresent" ,
257
+ Group : "testnotpresent.example.com" ,
258
+ Version : "unknown" ,
259
+ })
231
260
232
261
result = checkOwnedCSVStatusDescriptor (cr , & csv , result )
233
262
Expect (result .State ).To (Equal (scapiv1alpha3 .FailState ))
234
263
})
235
264
236
- It ("should fail when required descriptor field is not present in CR " , func () {
265
+ It ("should fail when CR does not have GVK set " , func () {
237
266
cr := unstructured.Unstructured {
238
267
Object : map [string ]interface {}{
239
- "node " : map [string ]interface {}{
240
- "node " : "val" ,
268
+ "status " : map [string ]interface {}{
269
+ "status " : "val" ,
241
270
},
242
271
},
243
272
}
244
273
245
274
result = checkOwnedCSVStatusDescriptor (cr , & csv , result )
246
275
Expect (result .State ).To (Equal (scapiv1alpha3 .FailState ))
247
276
})
248
- It ("should pass when required descriptor field is present in CR" , func () {
277
+
278
+ It ("should fail when required spec descriptor field is not present in CR" , func () {
249
279
cr := unstructured.Unstructured {
250
280
Object : map [string ]interface {}{
251
- "status" : map [string ]interface {}{
252
- "status" : "val" ,
253
- },
254
281
"spec" : map [string ]interface {}{
255
- "spec " : "val" ,
282
+ "node " : "val" ,
256
283
},
257
284
},
258
285
}
259
286
cr .SetGroupVersionKind (schema.GroupVersionKind {
260
- Kind : "TestKind" ,
261
- Group : "test.example.com" ,
287
+ Kind : "TestKind" ,
288
+ Group : "test.example.com" ,
289
+ Version : "v1" ,
262
290
})
263
291
264
- result = checkOwnedCSVSpecDescriptors (cr , & csv , result )
265
- Expect (result .State ).To (Equal (scapiv1alpha3 .PassState ))
266
- })
267
- It ("should fail when required spec descriptor field is not present in CR" , func () {
268
- cr := unstructured.Unstructured {
269
- Object : map [string ]interface {}{
270
- "status" : map [string ]interface {}{
271
- "status" : "val" ,
272
- },
273
- },
274
- }
275
-
276
292
result = checkOwnedCSVSpecDescriptors (cr , & csv , result )
277
293
Expect (result .State ).To (Equal (scapiv1alpha3 .FailState ))
278
294
})
279
- It ("should fail when CRs do not have spec field specified" , func () {
295
+
296
+ It ("should pass when CRs have spec field specified" , func () {
280
297
cr := []unstructured.Unstructured {
281
- unstructured.Unstructured {
282
- Object : map [string ]interface {}{},
298
+ {
299
+ Object : map [string ]interface {}{
300
+ "spec" : map [string ]interface {}{
301
+ "spec" : "val" ,
302
+ },
303
+ },
283
304
},
284
305
}
285
306
result = checkSpec (cr , result )
286
307
Expect (result .State ).To (Equal (scapiv1alpha3 .PassState ))
287
308
})
288
- It ("should pass when CRs do have spec field specified" , func () {
309
+
310
+ It ("should pass with warning when CRs do not have spec field specified" , func () {
289
311
cr := []unstructured.Unstructured {
290
- unstructured.Unstructured {
291
- Object : map [string ]interface {}{
292
- "spec" : map [string ]interface {}{
293
- "spec" : "val" ,
294
- },
295
- },
312
+ {
313
+ Object : map [string ]interface {}{},
296
314
},
297
315
}
298
316
result = checkSpec (cr , result )
299
317
Expect (result .State ).To (Equal (scapiv1alpha3 .PassState ))
318
+ Expect (result .Suggestions ).To (HaveLen (1 ))
300
319
})
301
320
302
321
})
0 commit comments