@@ -589,6 +589,20 @@ func TestExecuteForDefaultServers(t *testing.T) {
589589 }
590590}
591591
592+ func getHeaderMatchType (matchType string ) dataplane.MatchType {
593+ if len (matchType ) == 0 {
594+ return dataplane .MatchTypeExact
595+ }
596+ return dataplane .MatchType (matchType )
597+ }
598+
599+ func getQueryParamMatchType (matchType string ) dataplane.MatchType {
600+ if len (matchType ) == 0 {
601+ return dataplane .MatchTypeExact
602+ }
603+ return dataplane .MatchType (matchType )
604+ }
605+
592606func TestCreateServers (t * testing.T ) {
593607 t .Parallel ()
594608 const (
@@ -710,25 +724,30 @@ func TestCreateServers(t *testing.T) {
710724 {
711725 Name : "Version" ,
712726 Value : "V1" ,
727+ Type : getHeaderMatchType ("" ),
713728 },
714729 {
715730 Name : "test" ,
716731 Value : "foo" ,
732+ Type : getHeaderMatchType ("" ),
717733 },
718734 {
719735 Name : "my-header" ,
720736 Value : "my-value" ,
737+ Type : getHeaderMatchType ("" ),
721738 },
722739 },
723740 QueryParams : []dataplane.HTTPQueryParamMatch {
724741 {
725742 // query names and values should not be normalized to lowercase
726743 Name : "GrEat" ,
727744 Value : "EXAMPLE" ,
745+ Type : getQueryParamMatchType ("" ),
728746 },
729747 {
730748 Name : "test" ,
731749 Value : "foo=bar" ,
750+ Type : getQueryParamMatchType ("" ),
732751 },
733752 },
734753 },
@@ -797,6 +816,7 @@ func TestCreateServers(t *testing.T) {
797816 {
798817 Name : "redirect" ,
799818 Value : "this" ,
819+ Type : getHeaderMatchType ("" ),
800820 },
801821 },
802822 },
@@ -839,6 +859,7 @@ func TestCreateServers(t *testing.T) {
839859 {
840860 Name : "rewrite" ,
841861 Value : "this" ,
862+ Type : getHeaderMatchType ("" ),
842863 },
843864 },
844865 },
@@ -878,6 +899,7 @@ func TestCreateServers(t *testing.T) {
878899 {
879900 Name : "filter" ,
880901 Value : "this" ,
902+ Type : getHeaderMatchType ("" ),
881903 },
882904 },
883905 },
@@ -2702,14 +2724,17 @@ func TestCreateRouteMatch(t *testing.T) {
27022724 {
27032725 Name : "header-1" ,
27042726 Value : "val-1" ,
2727+ Type : getHeaderMatchType ("" ),
27052728 },
27062729 {
27072730 Name : "header-2" ,
27082731 Value : "val-2" ,
2732+ Type : getHeaderMatchType ("" ),
27092733 },
27102734 {
27112735 Name : "header-3" ,
27122736 Value : "val-3" ,
2737+ Type : getHeaderMatchType ("" ),
27132738 },
27142739 }
27152740
@@ -2725,14 +2750,17 @@ func TestCreateRouteMatch(t *testing.T) {
27252750 {
27262751 Name : "arg1" ,
27272752 Value : "val1" ,
2753+ Type : getQueryParamMatchType ("" ),
27282754 },
27292755 {
27302756 Name : "arg2" ,
27312757 Value : "val2=another-val" ,
2758+ Type : getQueryParamMatchType ("" ),
27322759 },
27332760 {
27342761 Name : "arg3" ,
27352762 Value : "==val3" ,
2763+ Type : getQueryParamMatchType ("" ),
27362764 },
27372765 }
27382766
@@ -2856,31 +2884,49 @@ func TestCreateRouteMatch(t *testing.T) {
28562884
28572885func TestCreateQueryParamKeyValString (t * testing.T ) {
28582886 t .Parallel ()
2859- g := NewWithT (t )
28602887
2861- expected := "key=Exact=value"
2862-
2863- result := createQueryParamKeyValString (
2864- dataplane.HTTPQueryParamMatch {
2865- Name : "key" ,
2866- Value : "value" ,
2867- Type : dataplane .MatchTypeExact ,
2888+ tests := []struct {
2889+ msg string
2890+ input dataplane.HTTPQueryParamMatch
2891+ expected string
2892+ }{
2893+ {
2894+ msg : "Exact match" ,
2895+ input : dataplane.HTTPQueryParamMatch {
2896+ Name : "key" ,
2897+ Value : "value" ,
2898+ Type : getQueryParamMatchType (string (dataplane .MatchTypeExact )),
2899+ },
2900+ expected : "key=Exact=value" ,
28682901 },
2869- )
2870-
2871- g .Expect (result ).To (Equal (expected ))
2872-
2873- expected = "KeY=RegularExpression=vaLUe-[a-z]=="
2874-
2875- result = createQueryParamKeyValString (
2876- dataplane.HTTPQueryParamMatch {
2877- Name : "KeY" ,
2878- Value : "vaLUe-[a-z]==" ,
2879- Type : dataplane .MatchTypeRegularExpression ,
2902+ {
2903+ msg : "RegularExpression match" ,
2904+ input : dataplane.HTTPQueryParamMatch {
2905+ Name : "KeY" ,
2906+ Value : "vaLUe-[a-z]==" ,
2907+ Type : getQueryParamMatchType (string (dataplane .MatchTypeRegularExpression )),
2908+ },
2909+ expected : "KeY=RegularExpression=vaLUe-[a-z]==" ,
28802910 },
2881- )
2911+ {
2912+ msg : "empty match type" ,
2913+ input : dataplane.HTTPQueryParamMatch {
2914+ Name : "keY" ,
2915+ Value : "vaLUe==" ,
2916+ Type : getQueryParamMatchType ("" ),
2917+ },
2918+ expected : "keY=Exact=vaLUe==" ,
2919+ },
2920+ }
28822921
2883- g .Expect (result ).To (Equal (expected ))
2922+ for _ , tc := range tests {
2923+ t .Run (tc .msg , func (t * testing.T ) {
2924+ t .Parallel ()
2925+ g := NewWithT (t )
2926+ result := createQueryParamKeyValString (tc .input )
2927+ g .Expect (result ).To (Equal (tc .expected ))
2928+ })
2929+ }
28842930}
28852931
28862932func TestCreateHeaderKeyValString (t * testing.T ) {
@@ -2893,7 +2939,7 @@ func TestCreateHeaderKeyValString(t *testing.T) {
28932939 dataplane.HTTPHeaderMatch {
28942940 Name : "kEy" ,
28952941 Value : "vALUe" ,
2896- Type : dataplane .MatchTypeExact ,
2942+ Type : getHeaderMatchType ( string ( dataplane .MatchTypeExact )) ,
28972943 },
28982944 )
28992945
@@ -2905,7 +2951,7 @@ func TestCreateHeaderKeyValString(t *testing.T) {
29052951 dataplane.HTTPHeaderMatch {
29062952 Name : "kEy" ,
29072953 Value : "vALUe-[0-9]" ,
2908- Type : dataplane .MatchTypeRegularExpression ,
2954+ Type : getHeaderMatchType ( string ( dataplane .MatchTypeRegularExpression )) ,
29092955 },
29102956 )
29112957
0 commit comments