@@ -302,3 +302,220 @@ func TestIsDefaultAnnotation(t *testing.T) {
302302 }
303303 }
304304}
305+
306+ func TestShouldEnqueueContentChange (t * testing.T ) {
307+ oldValue := "old"
308+ newValue := "new"
309+
310+ testcases := []struct {
311+ name string
312+ old * crdv1.VolumeSnapshotContent
313+ new * crdv1.VolumeSnapshotContent
314+ expectedResult bool
315+ }{
316+ {
317+ name : "basic no change" ,
318+ old : & crdv1.VolumeSnapshotContent {},
319+ new : & crdv1.VolumeSnapshotContent {},
320+ expectedResult : false ,
321+ },
322+ {
323+ name : "basic change" ,
324+ old : & crdv1.VolumeSnapshotContent {
325+ Spec : crdv1.VolumeSnapshotContentSpec {
326+ VolumeSnapshotClassName : & oldValue ,
327+ },
328+ },
329+ new : & crdv1.VolumeSnapshotContent {
330+ Spec : crdv1.VolumeSnapshotContentSpec {
331+ VolumeSnapshotClassName : & newValue ,
332+ },
333+ },
334+ expectedResult : true ,
335+ },
336+ {
337+ name : "status change" ,
338+ old : & crdv1.VolumeSnapshotContent {
339+ Status : & crdv1.VolumeSnapshotContentStatus {
340+ Error : & crdv1.VolumeSnapshotError {
341+ Message : & oldValue ,
342+ },
343+ },
344+ },
345+ new : & crdv1.VolumeSnapshotContent {
346+ Status : & crdv1.VolumeSnapshotContentStatus {
347+ Error : & crdv1.VolumeSnapshotError {
348+ Message : & newValue ,
349+ },
350+ },
351+ },
352+ expectedResult : false ,
353+ },
354+ {
355+ name : "finalizers change" ,
356+ old : & crdv1.VolumeSnapshotContent {
357+ ObjectMeta : metav1.ObjectMeta {
358+ Finalizers : []string {
359+ oldValue ,
360+ },
361+ },
362+ },
363+ new : & crdv1.VolumeSnapshotContent {
364+ ObjectMeta : metav1.ObjectMeta {
365+ Finalizers : []string {
366+ newValue ,
367+ },
368+ },
369+ },
370+ expectedResult : false ,
371+ },
372+ {
373+ name : "managed fields change" ,
374+ old : & crdv1.VolumeSnapshotContent {
375+ ObjectMeta : metav1.ObjectMeta {
376+ ManagedFields : []metav1.ManagedFieldsEntry {
377+ {
378+ Manager : oldValue ,
379+ },
380+ },
381+ },
382+ },
383+ new : & crdv1.VolumeSnapshotContent {
384+ ObjectMeta : metav1.ObjectMeta {
385+ ManagedFields : []metav1.ManagedFieldsEntry {
386+ {
387+ Manager : newValue ,
388+ },
389+ },
390+ },
391+ },
392+ expectedResult : false ,
393+ },
394+ {
395+ name : "sidecar-managed annotation change" ,
396+ old : & crdv1.VolumeSnapshotContent {
397+ ObjectMeta : metav1.ObjectMeta {
398+ Annotations : map [string ]string {
399+ AnnVolumeSnapshotBeingCreated : oldValue ,
400+ },
401+ },
402+ },
403+ new : & crdv1.VolumeSnapshotContent {
404+ ObjectMeta : metav1.ObjectMeta {
405+ Annotations : map [string ]string {
406+ AnnVolumeSnapshotBeingCreated : newValue ,
407+ },
408+ },
409+ },
410+ expectedResult : false ,
411+ },
412+ {
413+ name : "sidecar-unmanaged annotation change" ,
414+ old : & crdv1.VolumeSnapshotContent {
415+ ObjectMeta : metav1.ObjectMeta {
416+ Annotations : map [string ]string {
417+ "test-annotation" : oldValue ,
418+ },
419+ },
420+ },
421+ new : & crdv1.VolumeSnapshotContent {
422+ ObjectMeta : metav1.ObjectMeta {
423+ Annotations : map [string ]string {
424+ "test-annotation" : newValue ,
425+ },
426+ },
427+ },
428+ expectedResult : true ,
429+ },
430+ {
431+ name : "sidecar-managed annotation created" ,
432+ old : & crdv1.VolumeSnapshotContent {
433+ ObjectMeta : metav1.ObjectMeta {
434+ Annotations : nil ,
435+ },
436+ },
437+ new : & crdv1.VolumeSnapshotContent {
438+ ObjectMeta : metav1.ObjectMeta {
439+ Annotations : map [string ]string {
440+ AnnVolumeSnapshotBeingCreated : newValue ,
441+ },
442+ },
443+ },
444+ expectedResult : false ,
445+ },
446+ {
447+ name : "sidecar-unmanaged annotation created" ,
448+ old : & crdv1.VolumeSnapshotContent {
449+ ObjectMeta : metav1.ObjectMeta {
450+ Annotations : nil ,
451+ },
452+ },
453+ new : & crdv1.VolumeSnapshotContent {
454+ ObjectMeta : metav1.ObjectMeta {
455+ Annotations : map [string ]string {
456+ "test-annotation" : newValue ,
457+ },
458+ },
459+ },
460+ expectedResult : true ,
461+ },
462+ {
463+ name : "sidecar-managed annotation deleted" ,
464+ old : & crdv1.VolumeSnapshotContent {
465+ ObjectMeta : metav1.ObjectMeta {
466+ Annotations : map [string ]string {
467+ AnnVolumeSnapshotBeingCreated : oldValue ,
468+ },
469+ },
470+ },
471+ new : & crdv1.VolumeSnapshotContent {
472+ ObjectMeta : metav1.ObjectMeta {
473+ Annotations : nil ,
474+ },
475+ },
476+ expectedResult : false ,
477+ },
478+ {
479+ name : "sidecar-unmanaged annotation deleted" ,
480+ old : & crdv1.VolumeSnapshotContent {
481+ ObjectMeta : metav1.ObjectMeta {
482+ Annotations : map [string ]string {
483+ "test-annotation" : oldValue ,
484+ },
485+ },
486+ },
487+ new : & crdv1.VolumeSnapshotContent {
488+ ObjectMeta : metav1.ObjectMeta {
489+ Annotations : nil ,
490+ },
491+ },
492+ expectedResult : true ,
493+ },
494+ {
495+ name : "sidecar-unmanaged annotation change (AnnVolumeSnapshotBeingDeleted)" ,
496+ old : & crdv1.VolumeSnapshotContent {
497+ ObjectMeta : metav1.ObjectMeta {
498+ Annotations : map [string ]string {
499+ AnnVolumeSnapshotBeingDeleted : oldValue ,
500+ },
501+ },
502+ },
503+ new : & crdv1.VolumeSnapshotContent {
504+ ObjectMeta : metav1.ObjectMeta {
505+ Annotations : map [string ]string {
506+ AnnVolumeSnapshotBeingDeleted : newValue ,
507+ },
508+ },
509+ },
510+ expectedResult : true ,
511+ },
512+ }
513+ for _ , tc := range testcases {
514+ t .Run (tc .name , func (t * testing.T ) {
515+ result := ShouldEnqueueContentChange (tc .old , tc .new )
516+ if result != tc .expectedResult {
517+ t .Fatalf ("Incorrect result: Expected %v received %v" , tc .expectedResult , result )
518+ }
519+ })
520+ }
521+ }
0 commit comments