@@ -511,6 +511,16 @@ var _ = Describe("Metautils", func() {
511
511
})
512
512
})
513
513
514
+ DescribeTable ("HasLabel" ,
515
+ func (initLabels map [string ]string , key string , expected bool ) {
516
+ obj := & metav1.ObjectMeta {Labels : initLabels }
517
+ Expect (HasLabel (obj , key )).To (Equal (expected ))
518
+ },
519
+ Entry ("label present" , map [string ]string {"foo" : "" }, "foo" , true ),
520
+ Entry ("nil labels" , nil , "foo" , false ),
521
+ Entry ("different label present" , map [string ]string {"bar" : "" }, "foo" , false ),
522
+ )
523
+
514
524
DescribeTable ("SetLabel" ,
515
525
func (initLabels map [string ]string , key , value string , expected map [string ]string ) {
516
526
obj := & metav1.ObjectMeta {Labels : initLabels }
@@ -534,6 +544,39 @@ var _ = Describe("Metautils", func() {
534
544
Entry ("partial other keys, same key" , map [string ]string {"foo" : "baz" , "bar" : "baz" }, map [string ]string {"foo" : "bar" }, map [string ]string {"foo" : "bar" , "bar" : "baz" }),
535
545
)
536
546
547
+ DescribeTable ("DeleteLabel" ,
548
+ func (initLabels map [string ]string , key string , expected map [string ]string ) {
549
+ obj := & metav1.ObjectMeta {Labels : initLabels }
550
+ DeleteLabel (obj , key )
551
+ Expect (obj .Labels ).To (Equal (expected ))
552
+ },
553
+ Entry ("key present" , map [string ]string {"foo" : "bar" }, "foo" , map [string ]string {}),
554
+ Entry ("different key present" , map [string ]string {"bar" : "baz" }, "foo" , map [string ]string {"bar" : "baz" }),
555
+ Entry ("nil map" , nil , "foo" , nil ),
556
+ )
557
+
558
+ DescribeTable ("DeleteLabels" ,
559
+ func (initLabels map [string ]string , keys []string , expected map [string ]string ) {
560
+ obj := & metav1.ObjectMeta {Labels : initLabels }
561
+ DeleteLabels (obj , keys )
562
+ Expect (obj .Labels ).To (Equal (expected ))
563
+ },
564
+ Entry ("keys present" , map [string ]string {"foo" : "bar" , "bar" : "baz" }, []string {"foo" , "bar" }, map [string ]string {}),
565
+ Entry ("some keys present" , map [string ]string {"foo" : "bar" , "bar" : "baz" }, []string {"foo" }, map [string ]string {"bar" : "baz" }),
566
+ Entry ("no keys present" , map [string ]string {"foo" : "bar" , "bar" : "baz" }, []string {"qux" }, map [string ]string {"foo" : "bar" , "bar" : "baz" }),
567
+ Entry ("nil map" , nil , []string {"foo" , "bar" }, nil ),
568
+ )
569
+
570
+ DescribeTable ("HasAnnotation" ,
571
+ func (initAnnotations map [string ]string , key string , expected bool ) {
572
+ obj := & metav1.ObjectMeta {Annotations : initAnnotations }
573
+ Expect (HasAnnotation (obj , key )).To (Equal (expected ))
574
+ },
575
+ Entry ("annotation present" , map [string ]string {"foo" : "" }, "foo" , true ),
576
+ Entry ("nil annotations" , nil , "foo" , false ),
577
+ Entry ("different annotation present" , map [string ]string {"bar" : "" }, "foo" , false ),
578
+ )
579
+
537
580
DescribeTable ("SetAnnotation" ,
538
581
func (initAnnotations map [string ]string , key , value string , expected map [string ]string ) {
539
582
obj := & metav1.ObjectMeta {Annotations : initAnnotations }
@@ -557,6 +600,29 @@ var _ = Describe("Metautils", func() {
557
600
Entry ("partial other keys, same key" , map [string ]string {"foo" : "baz" , "bar" : "baz" }, map [string ]string {"foo" : "bar" }, map [string ]string {"foo" : "bar" , "bar" : "baz" }),
558
601
)
559
602
603
+ DescribeTable ("DeleteAnnotation" ,
604
+ func (initAnnotations map [string ]string , key string , expected map [string ]string ) {
605
+ obj := & metav1.ObjectMeta {Annotations : initAnnotations }
606
+ DeleteAnnotation (obj , key )
607
+ Expect (obj .Annotations ).To (Equal (expected ))
608
+ },
609
+ Entry ("key present" , map [string ]string {"foo" : "bar" }, "foo" , map [string ]string {}),
610
+ Entry ("different key present" , map [string ]string {"bar" : "baz" }, "foo" , map [string ]string {"bar" : "baz" }),
611
+ Entry ("nil map" , nil , "foo" , nil ),
612
+ )
613
+
614
+ DescribeTable ("DeleteAnnotations" ,
615
+ func (initAnnotations map [string ]string , keys []string , expected map [string ]string ) {
616
+ obj := & metav1.ObjectMeta {Annotations : initAnnotations }
617
+ DeleteAnnotations (obj , keys )
618
+ Expect (obj .Annotations ).To (Equal (expected ))
619
+ },
620
+ Entry ("keys present" , map [string ]string {"foo" : "bar" , "bar" : "baz" }, []string {"foo" , "bar" }, map [string ]string {}),
621
+ Entry ("some keys present" , map [string ]string {"foo" : "bar" , "bar" : "baz" }, []string {"foo" }, map [string ]string {"bar" : "baz" }),
622
+ Entry ("no keys present" , map [string ]string {"foo" : "bar" , "bar" : "baz" }, []string {"qux" }, map [string ]string {"foo" : "bar" , "bar" : "baz" }),
623
+ Entry ("nil map" , nil , []string {"foo" , "bar" }, nil ),
624
+ )
625
+
560
626
Describe ("FilterList" , func () {
561
627
It ("should filter the list with the given function" , func () {
562
628
list := & corev1.SecretList {
0 commit comments