@@ -630,3 +630,81 @@ func BenchmarkSelectorFromValidatedSet(b *testing.B) {
630
630
}
631
631
}
632
632
}
633
+
634
+ func TestRequiresExactMatch (t * testing.T ) {
635
+ testCases := []struct {
636
+ name string
637
+ sel Selector
638
+ label string
639
+ expectedFound bool
640
+ expectedValue string
641
+ }{
642
+ {
643
+ name : "keyInOperatorExactMatch" ,
644
+ sel : internalSelector {Requirement {"key" , selection .In , []string {"value" }}},
645
+ label : "key" ,
646
+ expectedFound : true ,
647
+ expectedValue : "value" ,
648
+ },
649
+ {
650
+ name : "keyInOperatorNotExactMatch" ,
651
+ sel : internalSelector {Requirement {"key" , selection .In , []string {"value" , "value2" }}},
652
+ label : "key" ,
653
+ expectedFound : false ,
654
+ expectedValue : "" ,
655
+ },
656
+ {
657
+ name : "keyInOperatorNotExactMatch" ,
658
+ sel : internalSelector {
659
+ Requirement {"key" , selection .In , []string {"value" , "value1" }},
660
+ Requirement {"key2" , selection .In , []string {"value2" }},
661
+ },
662
+ label : "key2" ,
663
+ expectedFound : true ,
664
+ expectedValue : "value2" ,
665
+ },
666
+ {
667
+ name : "keyEqualOperatorExactMatch" ,
668
+ sel : internalSelector {Requirement {"key" , selection .Equals , []string {"value" }}},
669
+ label : "key" ,
670
+ expectedFound : true ,
671
+ expectedValue : "value" ,
672
+ },
673
+ {
674
+ name : "keyDoubleEqualOperatorExactMatch" ,
675
+ sel : internalSelector {Requirement {"key" , selection .DoubleEquals , []string {"value" }}},
676
+ label : "key" ,
677
+ expectedFound : true ,
678
+ expectedValue : "value" ,
679
+ },
680
+ {
681
+ name : "keyNotEqualOperatorExactMatch" ,
682
+ sel : internalSelector {Requirement {"key" , selection .NotEquals , []string {"value" }}},
683
+ label : "key" ,
684
+ expectedFound : false ,
685
+ expectedValue : "" ,
686
+ },
687
+ {
688
+ name : "keyEqualOperatorExactMatchFirst" ,
689
+ sel : internalSelector {
690
+ Requirement {"key" , selection .In , []string {"value" }},
691
+ Requirement {"key2" , selection .In , []string {"value2" }},
692
+ },
693
+ label : "key" ,
694
+ expectedFound : true ,
695
+ expectedValue : "value" ,
696
+ },
697
+ }
698
+ for _ , ts := range testCases {
699
+ t .Run (ts .name , func (t * testing.T ) {
700
+ value , found := ts .sel .RequiresExactMatch (ts .label )
701
+ if found != ts .expectedFound {
702
+ t .Errorf ("Expected match %v, found %v" , ts .expectedFound , found )
703
+ }
704
+ if found && value != ts .expectedValue {
705
+ t .Errorf ("Expected value %v, found %v" , ts .expectedValue , value )
706
+ }
707
+
708
+ })
709
+ }
710
+ }
0 commit comments