@@ -127,15 +127,25 @@ var _ = Describe("Basic and OLM tests", func() {
127127 Describe ("OLM Tests" , func () {
128128
129129 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 {
136131 Spec : operatorsv1alpha1.ClusterServiceVersionSpec {
137132 CustomResourceDefinitions : operatorsv1alpha1.CustomResourceDefinitions {
138133 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+ },
139149 operatorsv1alpha1.CRDDescription {
140150 Name : "Test" ,
141151 Version : "v1" ,
@@ -156,147 +166,156 @@ var _ = Describe("Basic and OLM tests", func() {
156166 },
157167 }
158168
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 ,
169172 }
170173 cr .SetGroupVersionKind (schema.GroupVersionKind {
171- Kind : "TestKind" ,
172- Group : "test.example.com" ,
174+ Kind : "TestKind" ,
175+ Group : "test.example.com" ,
176+ Version : "v1" ,
173177 })
174178
175179 result = checkOwnedCSVStatusDescriptor (cr , & csv , result )
176180 Expect (result .State ).To (Equal (scapiv1alpha3 .PassState ))
177181 })
178182
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 {
181185 Object : map [string ]interface {}{
186+ "status" : map [string ]interface {}{
187+ "status" : "val" ,
188+ },
182189 "spec" : map [string ]interface {}{
183190 "spec" : "val" ,
184191 },
185192 },
186193 }
187194 cr .SetGroupVersionKind (schema.GroupVersionKind {
188- Kind : "TestKind" ,
189- Group : "test.example.com" ,
195+ Kind : "TestKind" ,
196+ Group : "test.example.com" ,
197+ Version : "v1" ,
190198 })
191199
192200 result = checkOwnedCSVStatusDescriptor (cr , & csv , result )
193- Expect (result .Suggestions ).To (HaveLen (1 ))
194201 Expect (result .State ).To (Equal (scapiv1alpha3 .PassState ))
195202 })
196203
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 () {
198205 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+ },
200214 }
201215 cr .SetGroupVersionKind (schema.GroupVersionKind {
202- Kind : "TestKind" ,
203- Group : "test.example.com" ,
216+ Kind : "TestKind" ,
217+ Group : "test.example.com" ,
218+ Version : "v1" ,
204219 })
205220
206- result = checkOwnedCSVStatusDescriptor (cr , & csv , result )
221+ result = checkOwnedCSVSpecDescriptors (cr , & csv , result )
207222 Expect (result .State ).To (Equal (scapiv1alpha3 .PassState ))
208223 })
209224
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 () {
211226 cr := unstructured.Unstructured {
212- Object : nil ,
227+ Object : map [string ]interface {}{
228+ "spec" : map [string ]interface {}{
229+ "spec" : "val" ,
230+ },
231+ },
213232 }
214233 cr .SetGroupVersionKind (schema.GroupVersionKind {
215- Kind : "TestKindNotPresent" ,
216- Group : "testnotpresent.example.com" ,
234+ Kind : "TestKind" ,
235+ Group : "test.example.com" ,
236+ Version : "v1" ,
217237 })
218238
219239 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 ))
221242 })
222243
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 () {
224245 cr := unstructured.Unstructured {
225246 Object : map [string ]interface {}{
226247 "status" : map [string ]interface {}{
227248 "status" : "val" ,
228249 },
250+ "spec" : map [string ]interface {}{
251+ "spec" : "val" ,
252+ },
229253 },
230254 }
255+ cr .SetGroupVersionKind (schema.GroupVersionKind {
256+ Kind : "TestKindNotPresent" ,
257+ Group : "testnotpresent.example.com" ,
258+ Version : "unknown" ,
259+ })
231260
232261 result = checkOwnedCSVStatusDescriptor (cr , & csv , result )
233262 Expect (result .State ).To (Equal (scapiv1alpha3 .FailState ))
234263 })
235264
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 () {
237266 cr := unstructured.Unstructured {
238267 Object : map [string ]interface {}{
239- "node " : map [string ]interface {}{
240- "node " : "val" ,
268+ "status " : map [string ]interface {}{
269+ "status " : "val" ,
241270 },
242271 },
243272 }
244273
245274 result = checkOwnedCSVStatusDescriptor (cr , & csv , result )
246275 Expect (result .State ).To (Equal (scapiv1alpha3 .FailState ))
247276 })
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 () {
249279 cr := unstructured.Unstructured {
250280 Object : map [string ]interface {}{
251- "status" : map [string ]interface {}{
252- "status" : "val" ,
253- },
254281 "spec" : map [string ]interface {}{
255- "spec " : "val" ,
282+ "node " : "val" ,
256283 },
257284 },
258285 }
259286 cr .SetGroupVersionKind (schema.GroupVersionKind {
260- Kind : "TestKind" ,
261- Group : "test.example.com" ,
287+ Kind : "TestKind" ,
288+ Group : "test.example.com" ,
289+ Version : "v1" ,
262290 })
263291
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-
276292 result = checkOwnedCSVSpecDescriptors (cr , & csv , result )
277293 Expect (result .State ).To (Equal (scapiv1alpha3 .FailState ))
278294 })
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 () {
280297 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+ },
283304 },
284305 }
285306 result = checkSpec (cr , result )
286307 Expect (result .State ).To (Equal (scapiv1alpha3 .PassState ))
287308 })
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 () {
289311 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 {}{},
296314 },
297315 }
298316 result = checkSpec (cr , result )
299317 Expect (result .State ).To (Equal (scapiv1alpha3 .PassState ))
318+ Expect (result .Suggestions ).To (HaveLen (1 ))
300319 })
301320
302321 })
0 commit comments