@@ -130,11 +130,25 @@ func TestBuildConfiguration(t *testing.T) {
130130
131131 createInternalRoute := func (
132132 source * v1beta1.HTTPRoute ,
133+ listenerName string ,
133134 paths []pathAndType ,
134135 ) * graph.Route {
136+ hostnames := make ([]string , 0 , len (source .Spec .Hostnames ))
137+ for _ , h := range source .Spec .Hostnames {
138+ hostnames = append (hostnames , string (h ))
139+ }
135140 r := & graph.Route {
136141 Source : source ,
137142 Rules : createRules (source , paths ),
143+ ParentRefs : []graph.ParentRef {
144+ {
145+ Attachment : & graph.ParentRefAttachmentStatus {
146+ AcceptedHostnames : map [string ][]string {
147+ listenerName : hostnames ,
148+ },
149+ },
150+ },
151+ },
138152 }
139153 return r
140154 }
@@ -162,7 +176,7 @@ func TestBuildConfiguration(t *testing.T) {
162176 * v1beta1.HTTPRoute , []BackendGroup , * graph.Route ,
163177 ) {
164178 hr := createRoute (name , hostname , listenerName , paths ... )
165- route := createInternalRoute (hr , paths )
179+ route := createInternalRoute (hr , listenerName , paths )
166180 groups := createExpBackendGroupsForRoute (route )
167181 return hr , groups , route
168182 }
@@ -217,7 +231,7 @@ func TestBuildConfiguration(t *testing.T) {
217231 pathAndType {path : "/valid" , pathType : prefix }, pathAndType {path : invalidMatchesPath , pathType : prefix },
218232 )
219233
220- hr7 , hr7Groups , routeHR7 := createTestResources (
234+ hr7 , expHR7Groups , routeHR7 := createTestResources (
221235 "hr-7" ,
222236 "foo.example.com" ,
223237 "listener-80-1" ,
@@ -258,6 +272,8 @@ func TestBuildConfiguration(t *testing.T) {
258272 "listener-443-with-hostname" ,
259273 pathAndType {path : "/" , pathType : prefix },
260274 )
275+ // add extra attachment for this route for duplicate listener test
276+ httpsRouteHR5 .ParentRefs [0 ].Attachment .AcceptedHostnames ["listener-443-1" ] = []string {"example.com" }
261277
262278 httpsHR6 , expHTTPSHR6Groups , httpsRouteHR6 := createTestResources (
263279 "https-hr-6" ,
@@ -352,10 +368,9 @@ func TestBuildConfiguration(t *testing.T) {
352368 Source : & v1beta1.Gateway {},
353369 Listeners : map [string ]* graph.Listener {
354370 "listener-80-1" : {
355- Source : listener80 ,
356- Valid : true ,
357- Routes : map [types.NamespacedName ]* graph.Route {},
358- AcceptedHostnames : map [string ]struct {}{},
371+ Source : listener80 ,
372+ Valid : true ,
373+ Routes : map [types.NamespacedName ]* graph.Route {},
359374 },
360375 },
361376 },
@@ -381,18 +396,16 @@ func TestBuildConfiguration(t *testing.T) {
381396 Source : & v1beta1.Gateway {},
382397 Listeners : map [string ]* graph.Listener {
383398 "listener-443-1" : {
384- Source : listener443 , // nil hostname
385- Valid : true ,
386- Routes : map [types.NamespacedName ]* graph.Route {},
387- AcceptedHostnames : map [string ]struct {}{},
388- SecretPath : secretPath ,
399+ Source : listener443 , // nil hostname
400+ Valid : true ,
401+ Routes : map [types.NamespacedName ]* graph.Route {},
402+ SecretPath : secretPath ,
389403 },
390404 "listener-443-with-hostname" : {
391- Source : listener443WithHostname , // non-nil hostname
392- Valid : true ,
393- Routes : map [types.NamespacedName ]* graph.Route {},
394- AcceptedHostnames : map [string ]struct {}{},
395- SecretPath : secretPath ,
405+ Source : listener443WithHostname , // non-nil hostname
406+ Valid : true ,
407+ Routes : map [types.NamespacedName ]* graph.Route {},
408+ SecretPath : secretPath ,
396409 },
397410 },
398411 },
@@ -458,10 +471,6 @@ func TestBuildConfiguration(t *testing.T) {
458471 {Namespace : "test" , Name : "hr-1" }: routeHR1 ,
459472 {Namespace : "test" , Name : "hr-2" }: routeHR2 ,
460473 },
461- AcceptedHostnames : map [string ]struct {}{
462- "foo.example.com" : {},
463- "bar.example.com" : {},
464- },
465474 },
466475 },
467476 },
@@ -533,10 +542,6 @@ func TestBuildConfiguration(t *testing.T) {
533542 {Namespace : "test" , Name : "https-hr-1" }: httpsRouteHR1 ,
534543 {Namespace : "test" , Name : "https-hr-2" }: httpsRouteHR2 ,
535544 },
536- AcceptedHostnames : map [string ]struct {}{
537- "foo.example.com" : {},
538- "bar.example.com" : {},
539- },
540545 },
541546 "listener-443-with-hostname" : {
542547 Source : listener443WithHostname ,
@@ -545,9 +550,6 @@ func TestBuildConfiguration(t *testing.T) {
545550 Routes : map [types.NamespacedName ]* graph.Route {
546551 {Namespace : "test" , Name : "https-hr-5" }: httpsRouteHR5 ,
547552 },
548- AcceptedHostnames : map [string ]struct {}{
549- "example.com" : {},
550- },
551553 },
552554 },
553555 },
@@ -649,9 +651,6 @@ func TestBuildConfiguration(t *testing.T) {
649651 {Namespace : "test" , Name : "hr-3" }: routeHR3 ,
650652 {Namespace : "test" , Name : "hr-4" }: routeHR4 ,
651653 },
652- AcceptedHostnames : map [string ]struct {}{
653- "foo.example.com" : {},
654- },
655654 },
656655 "listener-443-1" : {
657656 Source : listener443 ,
@@ -661,9 +660,6 @@ func TestBuildConfiguration(t *testing.T) {
661660 {Namespace : "test" , Name : "https-hr-3" }: httpsRouteHR3 ,
662661 {Namespace : "test" , Name : "https-hr-4" }: httpsRouteHR4 ,
663662 },
664- AcceptedHostnames : map [string ]struct {}{
665- "foo.example.com" : {},
666- },
667663 },
668664 },
669665 },
@@ -815,9 +811,6 @@ func TestBuildConfiguration(t *testing.T) {
815811 Routes : map [types.NamespacedName ]* graph.Route {
816812 {Namespace : "test" , Name : "hr-1" }: routeHR1 ,
817813 },
818- AcceptedHostnames : map [string ]struct {}{
819- "foo.example.com" : {},
820- },
821814 },
822815 },
823816 },
@@ -840,9 +833,6 @@ func TestBuildConfiguration(t *testing.T) {
840833 Routes : map [types.NamespacedName ]* graph.Route {
841834 {Namespace : "test" , Name : "hr-1" }: routeHR1 ,
842835 },
843- AcceptedHostnames : map [string ]struct {}{
844- "foo.example.com" : {},
845- },
846836 },
847837 },
848838 },
@@ -880,9 +870,6 @@ func TestBuildConfiguration(t *testing.T) {
880870 Routes : map [types.NamespacedName ]* graph.Route {
881871 {Namespace : "test" , Name : "hr-5" }: routeHR5 ,
882872 },
883- AcceptedHostnames : map [string ]struct {}{
884- "foo.example.com" : {},
885- },
886873 },
887874 },
888875 },
@@ -952,9 +939,6 @@ func TestBuildConfiguration(t *testing.T) {
952939 Routes : map [types.NamespacedName ]* graph.Route {
953940 {Namespace : "test" , Name : "hr-6" }: routeHR6 ,
954941 },
955- AcceptedHostnames : map [string ]struct {}{
956- "foo.example.com" : {},
957- },
958942 },
959943 "listener-443-1" : {
960944 Source : listener443 ,
@@ -963,9 +947,6 @@ func TestBuildConfiguration(t *testing.T) {
963947 Routes : map [types.NamespacedName ]* graph.Route {
964948 {Namespace : "test" , Name : "https-hr-6" }: httpsRouteHR6 ,
965949 },
966- AcceptedHostnames : map [string ]struct {}{
967- "foo.example.com" : {},
968- },
969950 },
970951 },
971952 },
@@ -1049,9 +1030,6 @@ func TestBuildConfiguration(t *testing.T) {
10491030 Routes : map [types.NamespacedName ]* graph.Route {
10501031 {Namespace : "test" , Name : "hr-7" }: routeHR7 ,
10511032 },
1052- AcceptedHostnames : map [string ]struct {}{
1053- "foo.example.com" : {},
1054- },
10551033 },
10561034 },
10571035 },
@@ -1074,7 +1052,7 @@ func TestBuildConfiguration(t *testing.T) {
10741052 {
10751053 MatchIdx : 0 ,
10761054 RuleIdx : 1 ,
1077- BackendGroup : hr7Groups [1 ],
1055+ BackendGroup : expHR7Groups [1 ],
10781056 Source : hr7 ,
10791057 },
10801058 },
@@ -1086,7 +1064,7 @@ func TestBuildConfiguration(t *testing.T) {
10861064 {
10871065 MatchIdx : 0 ,
10881066 RuleIdx : 0 ,
1089- BackendGroup : hr7Groups [0 ],
1067+ BackendGroup : expHR7Groups [0 ],
10901068 Source : hr7 ,
10911069 },
10921070 },
@@ -1096,7 +1074,7 @@ func TestBuildConfiguration(t *testing.T) {
10961074 },
10971075 SSLServers : []VirtualServer {},
10981076 Upstreams : []Upstream {fooUpstream },
1099- BackendGroups : []BackendGroup {hr7Groups [0 ], hr7Groups [1 ]},
1077+ BackendGroups : []BackendGroup {expHR7Groups [0 ], expHR7Groups [1 ]},
11001078 },
11011079 msg : "duplicate paths with different types" ,
11021080 },
@@ -1116,9 +1094,6 @@ func TestBuildConfiguration(t *testing.T) {
11161094 Routes : map [types.NamespacedName ]* graph.Route {
11171095 {Namespace : "test" , Name : "https-hr-5" }: httpsRouteHR5 ,
11181096 },
1119- AcceptedHostnames : map [string ]struct {}{
1120- "example.com" : {},
1121- },
11221097 },
11231098 "listener-443-1" : {
11241099 Source : listener443 ,
@@ -1127,9 +1102,6 @@ func TestBuildConfiguration(t *testing.T) {
11271102 Routes : map [types.NamespacedName ]* graph.Route {
11281103 {Namespace : "test" , Name : "https-hr-5" }: httpsRouteHR5 ,
11291104 },
1130- AcceptedHostnames : map [string ]struct {}{
1131- "example.com" : {},
1132- },
11331105 },
11341106 },
11351107 },
0 commit comments