@@ -308,4 +308,134 @@ var _ = Describe("Predicate", func() {
308
308
})
309
309
310
310
})
311
+
312
+ Describe ("When checking a GenerationChangedPredicate" , func () {
313
+ instance := predicate.GenerationChangedPredicate {}
314
+ Context ("Where the old object doesn't have a Generation or metadata" , func () {
315
+ It ("should return false" , func () {
316
+ new := & corev1.Pod {
317
+ ObjectMeta : metav1.ObjectMeta {
318
+ Name : "baz" ,
319
+ Namespace : "biz" ,
320
+ Generation : 1 ,
321
+ }}
322
+
323
+ failEvnt := event.UpdateEvent {
324
+ MetaNew : new .GetObjectMeta (),
325
+ ObjectNew : new ,
326
+ }
327
+ Expect (instance .Create (event.CreateEvent {})).To (BeTrue ())
328
+ Expect (instance .Delete (event.DeleteEvent {})).To (BeTrue ())
329
+ Expect (instance .Generic (event.GenericEvent {})).To (BeTrue ())
330
+ Expect (instance .Update (failEvnt )).To (BeFalse ())
331
+ })
332
+ })
333
+
334
+ Context ("Where the new object doesn't have a Generation or metadata" , func () {
335
+ It ("should return false" , func () {
336
+ old := & corev1.Pod {
337
+ ObjectMeta : metav1.ObjectMeta {
338
+ Name : "baz" ,
339
+ Namespace : "biz" ,
340
+ Generation : 1 ,
341
+ }}
342
+
343
+ failEvnt := event.UpdateEvent {
344
+ MetaOld : old .GetObjectMeta (),
345
+ ObjectOld : old ,
346
+ }
347
+ Expect (instance .Create (event.CreateEvent {})).To (BeTrue ())
348
+ Expect (instance .Delete (event.DeleteEvent {})).To (BeTrue ())
349
+ Expect (instance .Generic (event.GenericEvent {})).To (BeTrue ())
350
+ Expect (instance .Update (failEvnt )).To (BeFalse ())
351
+ })
352
+ })
353
+
354
+ Context ("Where the Generation hasn't changed" , func () {
355
+ It ("should return false" , func () {
356
+ new := & corev1.Pod {
357
+ ObjectMeta : metav1.ObjectMeta {
358
+ Name : "baz" ,
359
+ Namespace : "biz" ,
360
+ Generation : 1 ,
361
+ }}
362
+
363
+ old := & corev1.Pod {
364
+ ObjectMeta : metav1.ObjectMeta {
365
+ Name : "baz" ,
366
+ Namespace : "biz" ,
367
+ Generation : 1 ,
368
+ }}
369
+
370
+ failEvnt := event.UpdateEvent {
371
+ MetaOld : old .GetObjectMeta (),
372
+ ObjectOld : old ,
373
+ MetaNew : new .GetObjectMeta (),
374
+ ObjectNew : new ,
375
+ }
376
+ Expect (instance .Create (event.CreateEvent {})).To (BeTrue ())
377
+ Expect (instance .Delete (event.DeleteEvent {})).To (BeTrue ())
378
+ Expect (instance .Generic (event.GenericEvent {})).To (BeTrue ())
379
+ Expect (instance .Update (failEvnt )).To (BeFalse ())
380
+ })
381
+ })
382
+
383
+ Context ("Where the Generation has changed" , func () {
384
+ It ("should return true" , func () {
385
+ new := & corev1.Pod {
386
+ ObjectMeta : metav1.ObjectMeta {
387
+ Name : "baz" ,
388
+ Namespace : "biz" ,
389
+ Generation : 1 ,
390
+ }}
391
+
392
+ old := & corev1.Pod {
393
+ ObjectMeta : metav1.ObjectMeta {
394
+ Name : "baz" ,
395
+ Namespace : "biz" ,
396
+ Generation : 2 ,
397
+ }}
398
+ passEvt := event.UpdateEvent {
399
+ MetaOld : old .GetObjectMeta (),
400
+ ObjectOld : old ,
401
+ MetaNew : new .GetObjectMeta (),
402
+ ObjectNew : new ,
403
+ }
404
+ Expect (instance .Create (event.CreateEvent {})).To (BeTrue ())
405
+ Expect (instance .Delete (event.DeleteEvent {})).To (BeTrue ())
406
+ Expect (instance .Generic (event.GenericEvent {})).To (BeTrue ())
407
+ Expect (instance .Update (passEvt )).To (BeTrue ())
408
+ })
409
+ })
410
+
411
+ Context ("Where the objects or metadata are missing" , func () {
412
+
413
+ It ("should return false" , func () {
414
+ new := & corev1.Pod {
415
+ ObjectMeta : metav1.ObjectMeta {
416
+ Name : "baz" ,
417
+ Namespace : "biz" ,
418
+ Generation : 1 ,
419
+ }}
420
+
421
+ old := & corev1.Pod {
422
+ ObjectMeta : metav1.ObjectMeta {
423
+ Name : "baz" ,
424
+ Namespace : "biz" ,
425
+ Generation : 1 ,
426
+ }}
427
+
428
+ failEvt1 := event.UpdateEvent {MetaOld : old .GetObjectMeta (), ObjectOld : old , MetaNew : new .GetObjectMeta ()}
429
+ failEvt2 := event.UpdateEvent {MetaOld : old .GetObjectMeta (), MetaNew : new .GetObjectMeta (), ObjectNew : new }
430
+ failEvt3 := event.UpdateEvent {MetaOld : old .GetObjectMeta (), ObjectOld : old , ObjectNew : new }
431
+ Expect (instance .Create (event.CreateEvent {})).To (BeTrue ())
432
+ Expect (instance .Delete (event.DeleteEvent {})).To (BeTrue ())
433
+ Expect (instance .Generic (event.GenericEvent {})).To (BeTrue ())
434
+ Expect (instance .Update (failEvt1 )).To (BeFalse ())
435
+ Expect (instance .Update (failEvt2 )).To (BeFalse ())
436
+ Expect (instance .Update (failEvt3 )).To (BeFalse ())
437
+ })
438
+ })
439
+
440
+ })
311
441
})
0 commit comments