@@ -892,6 +892,41 @@ func TestCreateServersConflicts(t *testing.T) {
892892 return hr
893893 }
894894
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+
895930 fooGroup := dataplane.BackendGroup {
896931 Source : types.NamespacedName {Namespace : "test" , Name : "route" },
897932 RuleIdx : 0 ,
@@ -939,18 +974,9 @@ func TestCreateServersConflicts(t *testing.T) {
939974 PathType : dataplane .PathTypePrefix ,
940975 MatchRules : []dataplane.MatchRule {
941976 {
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 ,
954980 BackendGroup : fooGroup ,
955981 },
956982 },
@@ -960,18 +986,9 @@ func TestCreateServersConflicts(t *testing.T) {
960986 PathType : dataplane .PathTypeExact ,
961987 MatchRules : []dataplane.MatchRule {
962988 {
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 ,
975992 BackendGroup : barGroup ,
976993 },
977994 },
@@ -997,18 +1014,9 @@ func TestCreateServersConflicts(t *testing.T) {
9971014 PathType : dataplane .PathTypePrefix ,
9981015 MatchRules : []dataplane.MatchRule {
9991016 {
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 ,
10121020 BackendGroup : fooGroup ,
10131021 },
10141022 },
@@ -1018,18 +1026,9 @@ func TestCreateServersConflicts(t *testing.T) {
10181026 PathType : dataplane .PathTypePrefix ,
10191027 MatchRules : []dataplane.MatchRule {
10201028 {
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 ,
10331032 BackendGroup : barGroup ,
10341033 },
10351034 },
@@ -1055,22 +1054,9 @@ func TestCreateServersConflicts(t *testing.T) {
10551054 PathType : dataplane .PathTypePrefix ,
10561055 MatchRules : []dataplane.MatchRule {
10571056 {
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 ,
10741060 BackendGroup : fooGroup ,
10751061 },
10761062 },
@@ -1080,22 +1066,9 @@ func TestCreateServersConflicts(t *testing.T) {
10801066 PathType : dataplane .PathTypePrefix ,
10811067 MatchRules : []dataplane.MatchRule {
10821068 {
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 ,
10991072 BackendGroup : barGroup ,
11001073 },
11011074 },
@@ -1762,40 +1735,46 @@ func TestIsPathOnlyMatch(t *testing.T) {
17621735func TestCreateProxyPass (t * testing.T ) {
17631736 g := NewGomegaWithT (t )
17641737
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+ },
17731752 },
17741753 },
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+ },
17941770 },
17951771 },
17961772 }
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+ }
17991778}
18001779
18011780func TestCreateMatchLocation (t * testing.T ) {
0 commit comments