@@ -589,6 +589,20 @@ func TestExecuteForDefaultServers(t *testing.T) {
589
589
}
590
590
}
591
591
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
+
592
606
func TestCreateServers (t * testing.T ) {
593
607
t .Parallel ()
594
608
const (
@@ -710,25 +724,30 @@ func TestCreateServers(t *testing.T) {
710
724
{
711
725
Name : "Version" ,
712
726
Value : "V1" ,
727
+ Type : getHeaderMatchType ("" ),
713
728
},
714
729
{
715
730
Name : "test" ,
716
731
Value : "foo" ,
732
+ Type : getHeaderMatchType ("" ),
717
733
},
718
734
{
719
735
Name : "my-header" ,
720
736
Value : "my-value" ,
737
+ Type : getHeaderMatchType ("" ),
721
738
},
722
739
},
723
740
QueryParams : []dataplane.HTTPQueryParamMatch {
724
741
{
725
742
// query names and values should not be normalized to lowercase
726
743
Name : "GrEat" ,
727
744
Value : "EXAMPLE" ,
745
+ Type : getQueryParamMatchType ("" ),
728
746
},
729
747
{
730
748
Name : "test" ,
731
749
Value : "foo=bar" ,
750
+ Type : getQueryParamMatchType ("" ),
732
751
},
733
752
},
734
753
},
@@ -797,6 +816,7 @@ func TestCreateServers(t *testing.T) {
797
816
{
798
817
Name : "redirect" ,
799
818
Value : "this" ,
819
+ Type : getHeaderMatchType ("" ),
800
820
},
801
821
},
802
822
},
@@ -839,6 +859,7 @@ func TestCreateServers(t *testing.T) {
839
859
{
840
860
Name : "rewrite" ,
841
861
Value : "this" ,
862
+ Type : getHeaderMatchType ("" ),
842
863
},
843
864
},
844
865
},
@@ -878,6 +899,7 @@ func TestCreateServers(t *testing.T) {
878
899
{
879
900
Name : "filter" ,
880
901
Value : "this" ,
902
+ Type : getHeaderMatchType ("" ),
881
903
},
882
904
},
883
905
},
@@ -2702,14 +2724,17 @@ func TestCreateRouteMatch(t *testing.T) {
2702
2724
{
2703
2725
Name : "header-1" ,
2704
2726
Value : "val-1" ,
2727
+ Type : getHeaderMatchType ("" ),
2705
2728
},
2706
2729
{
2707
2730
Name : "header-2" ,
2708
2731
Value : "val-2" ,
2732
+ Type : getHeaderMatchType ("" ),
2709
2733
},
2710
2734
{
2711
2735
Name : "header-3" ,
2712
2736
Value : "val-3" ,
2737
+ Type : getHeaderMatchType ("" ),
2713
2738
},
2714
2739
}
2715
2740
@@ -2725,14 +2750,17 @@ func TestCreateRouteMatch(t *testing.T) {
2725
2750
{
2726
2751
Name : "arg1" ,
2727
2752
Value : "val1" ,
2753
+ Type : getQueryParamMatchType ("" ),
2728
2754
},
2729
2755
{
2730
2756
Name : "arg2" ,
2731
2757
Value : "val2=another-val" ,
2758
+ Type : getQueryParamMatchType ("" ),
2732
2759
},
2733
2760
{
2734
2761
Name : "arg3" ,
2735
2762
Value : "==val3" ,
2763
+ Type : getQueryParamMatchType ("" ),
2736
2764
},
2737
2765
}
2738
2766
@@ -2856,31 +2884,49 @@ func TestCreateRouteMatch(t *testing.T) {
2856
2884
2857
2885
func TestCreateQueryParamKeyValString (t * testing.T ) {
2858
2886
t .Parallel ()
2859
- g := NewWithT (t )
2860
2887
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" ,
2868
2901
},
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]==" ,
2880
2910
},
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
+ }
2882
2921
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
+ }
2884
2930
}
2885
2931
2886
2932
func TestCreateHeaderKeyValString (t * testing.T ) {
@@ -2893,7 +2939,7 @@ func TestCreateHeaderKeyValString(t *testing.T) {
2893
2939
dataplane.HTTPHeaderMatch {
2894
2940
Name : "kEy" ,
2895
2941
Value : "vALUe" ,
2896
- Type : dataplane .MatchTypeExact ,
2942
+ Type : getHeaderMatchType ( string ( dataplane .MatchTypeExact )) ,
2897
2943
},
2898
2944
)
2899
2945
@@ -2905,7 +2951,7 @@ func TestCreateHeaderKeyValString(t *testing.T) {
2905
2951
dataplane.HTTPHeaderMatch {
2906
2952
Name : "kEy" ,
2907
2953
Value : "vALUe-[0-9]" ,
2908
- Type : dataplane .MatchTypeRegularExpression ,
2954
+ Type : getHeaderMatchType ( string ( dataplane .MatchTypeRegularExpression )) ,
2909
2955
},
2910
2956
)
2911
2957
0 commit comments