@@ -892,6 +892,41 @@ func TestCreateServersConflicts(t *testing.T) {
892
892
return hr
893
893
}
894
894
895
+ hr1 := createHR ([]pathAndType {
896
+ {
897
+ path : "/coffee" ,
898
+ pathType : v1beta1 .PathMatchPathPrefix ,
899
+ },
900
+ {
901
+ path : "/coffee" ,
902
+ pathType : v1beta1 .PathMatchExact ,
903
+ },
904
+ })
905
+ hr2 := createHR ([]pathAndType {
906
+ {
907
+ path : "/coffee" ,
908
+ pathType : v1beta1 .PathMatchPathPrefix ,
909
+ },
910
+ {
911
+ path : "/coffee/" ,
912
+ pathType : v1beta1 .PathMatchPathPrefix ,
913
+ },
914
+ })
915
+ hr3 := createHR ([]pathAndType {
916
+ {
917
+ path : "/coffee" ,
918
+ pathType : v1beta1 .PathMatchPathPrefix ,
919
+ },
920
+ {
921
+ path : "/coffee/" ,
922
+ pathType : v1beta1 .PathMatchPathPrefix ,
923
+ },
924
+ {
925
+ path : "/coffee" ,
926
+ pathType : v1beta1 .PathMatchExact ,
927
+ },
928
+ })
929
+
895
930
fooGroup := dataplane.BackendGroup {
896
931
Source : types.NamespacedName {Namespace : "test" , Name : "route" },
897
932
RuleIdx : 0 ,
@@ -939,18 +974,9 @@ func TestCreateServersConflicts(t *testing.T) {
939
974
PathType : dataplane .PathTypePrefix ,
940
975
MatchRules : []dataplane.MatchRule {
941
976
{
942
- MatchIdx : 0 ,
943
- RuleIdx : 0 ,
944
- Source : createHR ([]pathAndType {
945
- {
946
- path : "/coffee" ,
947
- pathType : v1beta1 .PathMatchPathPrefix ,
948
- },
949
- {
950
- path : "/coffee" ,
951
- pathType : v1beta1 .PathMatchExact ,
952
- },
953
- }),
977
+ MatchIdx : 0 ,
978
+ RuleIdx : 0 ,
979
+ Source : hr1 ,
954
980
BackendGroup : fooGroup ,
955
981
},
956
982
},
@@ -960,18 +986,9 @@ func TestCreateServersConflicts(t *testing.T) {
960
986
PathType : dataplane .PathTypeExact ,
961
987
MatchRules : []dataplane.MatchRule {
962
988
{
963
- MatchIdx : 0 ,
964
- RuleIdx : 0 ,
965
- Source : createHR ([]pathAndType {
966
- {
967
- path : "/coffee" ,
968
- pathType : v1beta1 .PathMatchPathPrefix ,
969
- },
970
- {
971
- path : "/coffee" ,
972
- pathType : v1beta1 .PathMatchExact ,
973
- },
974
- }),
989
+ MatchIdx : 0 ,
990
+ RuleIdx : 0 ,
991
+ Source : hr1 ,
975
992
BackendGroup : barGroup ,
976
993
},
977
994
},
@@ -997,18 +1014,9 @@ func TestCreateServersConflicts(t *testing.T) {
997
1014
PathType : dataplane .PathTypePrefix ,
998
1015
MatchRules : []dataplane.MatchRule {
999
1016
{
1000
- MatchIdx : 0 ,
1001
- RuleIdx : 0 ,
1002
- Source : createHR ([]pathAndType {
1003
- {
1004
- path : "/coffee" ,
1005
- pathType : v1beta1 .PathMatchPathPrefix ,
1006
- },
1007
- {
1008
- path : "/coffee/" ,
1009
- pathType : v1beta1 .PathMatchPathPrefix ,
1010
- },
1011
- }),
1017
+ MatchIdx : 0 ,
1018
+ RuleIdx : 0 ,
1019
+ Source : hr2 ,
1012
1020
BackendGroup : fooGroup ,
1013
1021
},
1014
1022
},
@@ -1018,18 +1026,9 @@ func TestCreateServersConflicts(t *testing.T) {
1018
1026
PathType : dataplane .PathTypePrefix ,
1019
1027
MatchRules : []dataplane.MatchRule {
1020
1028
{
1021
- MatchIdx : 0 ,
1022
- RuleIdx : 1 ,
1023
- Source : createHR ([]pathAndType {
1024
- {
1025
- path : "/coffee" ,
1026
- pathType : v1beta1 .PathMatchPathPrefix ,
1027
- },
1028
- {
1029
- path : "/coffee/" ,
1030
- pathType : v1beta1 .PathMatchPathPrefix ,
1031
- },
1032
- }),
1029
+ MatchIdx : 0 ,
1030
+ RuleIdx : 1 ,
1031
+ Source : hr2 ,
1033
1032
BackendGroup : barGroup ,
1034
1033
},
1035
1034
},
@@ -1055,22 +1054,9 @@ func TestCreateServersConflicts(t *testing.T) {
1055
1054
PathType : dataplane .PathTypePrefix ,
1056
1055
MatchRules : []dataplane.MatchRule {
1057
1056
{
1058
- MatchIdx : 0 ,
1059
- RuleIdx : 0 ,
1060
- Source : createHR ([]pathAndType {
1061
- {
1062
- path : "/coffee" ,
1063
- pathType : v1beta1 .PathMatchPathPrefix ,
1064
- },
1065
- {
1066
- path : "/coffee/" ,
1067
- pathType : v1beta1 .PathMatchPathPrefix ,
1068
- },
1069
- {
1070
- path : "/coffee" ,
1071
- pathType : v1beta1 .PathMatchExact ,
1072
- },
1073
- }),
1057
+ MatchIdx : 0 ,
1058
+ RuleIdx : 0 ,
1059
+ Source : hr3 ,
1074
1060
BackendGroup : fooGroup ,
1075
1061
},
1076
1062
},
@@ -1080,22 +1066,9 @@ func TestCreateServersConflicts(t *testing.T) {
1080
1066
PathType : dataplane .PathTypePrefix ,
1081
1067
MatchRules : []dataplane.MatchRule {
1082
1068
{
1083
- MatchIdx : 0 ,
1084
- RuleIdx : 1 ,
1085
- Source : createHR ([]pathAndType {
1086
- {
1087
- path : "/coffee" ,
1088
- pathType : v1beta1 .PathMatchPathPrefix ,
1089
- },
1090
- {
1091
- path : "/coffee/" ,
1092
- pathType : v1beta1 .PathMatchPathPrefix ,
1093
- },
1094
- {
1095
- path : "/coffee" ,
1096
- pathType : v1beta1 .PathMatchExact ,
1097
- },
1098
- }),
1069
+ MatchIdx : 0 ,
1070
+ RuleIdx : 1 ,
1071
+ Source : hr3 ,
1099
1072
BackendGroup : barGroup ,
1100
1073
},
1101
1074
},
@@ -1762,40 +1735,46 @@ func TestIsPathOnlyMatch(t *testing.T) {
1762
1735
func TestCreateProxyPass (t * testing.T ) {
1763
1736
g := NewGomegaWithT (t )
1764
1737
1765
- expected := "http://10.0.0.1:80"
1766
-
1767
- grp := dataplane.BackendGroup {
1768
- Backends : []dataplane.Backend {
1769
- {
1770
- UpstreamName : "10.0.0.1:80" ,
1771
- Valid : true ,
1772
- Weight : 1 ,
1738
+ tests := []struct {
1739
+ expected string
1740
+ grp dataplane.BackendGroup
1741
+ }{
1742
+ {
1743
+ expected : "http://10.0.0.1:80" ,
1744
+ grp : dataplane.BackendGroup {
1745
+ Backends : []dataplane.Backend {
1746
+ {
1747
+ UpstreamName : "10.0.0.1:80" ,
1748
+ Valid : true ,
1749
+ Weight : 1 ,
1750
+ },
1751
+ },
1773
1752
},
1774
1753
},
1775
- }
1776
-
1777
- result := createProxyPass (grp )
1778
- g .Expect (result ).To (Equal (expected ))
1779
-
1780
- expected = "http://$ns1__bg_rule0"
1781
-
1782
- grp = dataplane.BackendGroup {
1783
- Source : types.NamespacedName {Namespace : "ns1" , Name : "bg" },
1784
- Backends : []dataplane.Backend {
1785
- {
1786
- UpstreamName : "my-variable" ,
1787
- Valid : true ,
1788
- Weight : 1 ,
1789
- },
1790
- {
1791
- UpstreamName : "my-variable2" ,
1792
- Valid : true ,
1793
- Weight : 1 ,
1754
+ {
1755
+ expected : "http://$ns1__bg_rule0" ,
1756
+ grp : dataplane.BackendGroup {
1757
+ Source : types.NamespacedName {Namespace : "ns1" , Name : "bg" },
1758
+ Backends : []dataplane.Backend {
1759
+ {
1760
+ UpstreamName : "my-variable" ,
1761
+ Valid : true ,
1762
+ Weight : 1 ,
1763
+ },
1764
+ {
1765
+ UpstreamName : "my-variable2" ,
1766
+ Valid : true ,
1767
+ Weight : 1 ,
1768
+ },
1769
+ },
1794
1770
},
1795
1771
},
1796
1772
}
1797
- result = createProxyPass (grp )
1798
- g .Expect (result ).To (Equal (expected ))
1773
+
1774
+ for _ , tc := range tests {
1775
+ result := createProxyPass (tc .grp )
1776
+ g .Expect (result ).To (Equal (tc .expected ))
1777
+ }
1799
1778
}
1800
1779
1801
1780
func TestCreateMatchLocation (t * testing.T ) {
0 commit comments