@@ -130,11 +130,25 @@ func TestBuildConfiguration(t *testing.T) {
130
130
131
131
createInternalRoute := func (
132
132
source * v1beta1.HTTPRoute ,
133
+ listenerName string ,
133
134
paths []pathAndType ,
134
135
) * 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
+ }
135
140
r := & graph.Route {
136
141
Source : source ,
137
142
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
+ },
138
152
}
139
153
return r
140
154
}
@@ -162,7 +176,7 @@ func TestBuildConfiguration(t *testing.T) {
162
176
* v1beta1.HTTPRoute , []BackendGroup , * graph.Route ,
163
177
) {
164
178
hr := createRoute (name , hostname , listenerName , paths ... )
165
- route := createInternalRoute (hr , paths )
179
+ route := createInternalRoute (hr , listenerName , paths )
166
180
groups := createExpBackendGroupsForRoute (route )
167
181
return hr , groups , route
168
182
}
@@ -217,7 +231,7 @@ func TestBuildConfiguration(t *testing.T) {
217
231
pathAndType {path : "/valid" , pathType : prefix }, pathAndType {path : invalidMatchesPath , pathType : prefix },
218
232
)
219
233
220
- hr7 , hr7Groups , routeHR7 := createTestResources (
234
+ hr7 , expHR7Groups , routeHR7 := createTestResources (
221
235
"hr-7" ,
222
236
"foo.example.com" ,
223
237
"listener-80-1" ,
@@ -258,6 +272,8 @@ func TestBuildConfiguration(t *testing.T) {
258
272
"listener-443-with-hostname" ,
259
273
pathAndType {path : "/" , pathType : prefix },
260
274
)
275
+ // add extra attachment for this route for duplicate listener test
276
+ httpsRouteHR5 .ParentRefs [0 ].Attachment .AcceptedHostnames ["listener-443-1" ] = []string {"example.com" }
261
277
262
278
httpsHR6 , expHTTPSHR6Groups , httpsRouteHR6 := createTestResources (
263
279
"https-hr-6" ,
@@ -352,10 +368,9 @@ func TestBuildConfiguration(t *testing.T) {
352
368
Source : & v1beta1.Gateway {},
353
369
Listeners : map [string ]* graph.Listener {
354
370
"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 {},
359
374
},
360
375
},
361
376
},
@@ -381,18 +396,16 @@ func TestBuildConfiguration(t *testing.T) {
381
396
Source : & v1beta1.Gateway {},
382
397
Listeners : map [string ]* graph.Listener {
383
398
"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 ,
389
403
},
390
404
"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 ,
396
409
},
397
410
},
398
411
},
@@ -458,10 +471,6 @@ func TestBuildConfiguration(t *testing.T) {
458
471
{Namespace : "test" , Name : "hr-1" }: routeHR1 ,
459
472
{Namespace : "test" , Name : "hr-2" }: routeHR2 ,
460
473
},
461
- AcceptedHostnames : map [string ]struct {}{
462
- "foo.example.com" : {},
463
- "bar.example.com" : {},
464
- },
465
474
},
466
475
},
467
476
},
@@ -533,10 +542,6 @@ func TestBuildConfiguration(t *testing.T) {
533
542
{Namespace : "test" , Name : "https-hr-1" }: httpsRouteHR1 ,
534
543
{Namespace : "test" , Name : "https-hr-2" }: httpsRouteHR2 ,
535
544
},
536
- AcceptedHostnames : map [string ]struct {}{
537
- "foo.example.com" : {},
538
- "bar.example.com" : {},
539
- },
540
545
},
541
546
"listener-443-with-hostname" : {
542
547
Source : listener443WithHostname ,
@@ -545,9 +550,6 @@ func TestBuildConfiguration(t *testing.T) {
545
550
Routes : map [types.NamespacedName ]* graph.Route {
546
551
{Namespace : "test" , Name : "https-hr-5" }: httpsRouteHR5 ,
547
552
},
548
- AcceptedHostnames : map [string ]struct {}{
549
- "example.com" : {},
550
- },
551
553
},
552
554
},
553
555
},
@@ -649,9 +651,6 @@ func TestBuildConfiguration(t *testing.T) {
649
651
{Namespace : "test" , Name : "hr-3" }: routeHR3 ,
650
652
{Namespace : "test" , Name : "hr-4" }: routeHR4 ,
651
653
},
652
- AcceptedHostnames : map [string ]struct {}{
653
- "foo.example.com" : {},
654
- },
655
654
},
656
655
"listener-443-1" : {
657
656
Source : listener443 ,
@@ -661,9 +660,6 @@ func TestBuildConfiguration(t *testing.T) {
661
660
{Namespace : "test" , Name : "https-hr-3" }: httpsRouteHR3 ,
662
661
{Namespace : "test" , Name : "https-hr-4" }: httpsRouteHR4 ,
663
662
},
664
- AcceptedHostnames : map [string ]struct {}{
665
- "foo.example.com" : {},
666
- },
667
663
},
668
664
},
669
665
},
@@ -815,9 +811,6 @@ func TestBuildConfiguration(t *testing.T) {
815
811
Routes : map [types.NamespacedName ]* graph.Route {
816
812
{Namespace : "test" , Name : "hr-1" }: routeHR1 ,
817
813
},
818
- AcceptedHostnames : map [string ]struct {}{
819
- "foo.example.com" : {},
820
- },
821
814
},
822
815
},
823
816
},
@@ -840,9 +833,6 @@ func TestBuildConfiguration(t *testing.T) {
840
833
Routes : map [types.NamespacedName ]* graph.Route {
841
834
{Namespace : "test" , Name : "hr-1" }: routeHR1 ,
842
835
},
843
- AcceptedHostnames : map [string ]struct {}{
844
- "foo.example.com" : {},
845
- },
846
836
},
847
837
},
848
838
},
@@ -880,9 +870,6 @@ func TestBuildConfiguration(t *testing.T) {
880
870
Routes : map [types.NamespacedName ]* graph.Route {
881
871
{Namespace : "test" , Name : "hr-5" }: routeHR5 ,
882
872
},
883
- AcceptedHostnames : map [string ]struct {}{
884
- "foo.example.com" : {},
885
- },
886
873
},
887
874
},
888
875
},
@@ -952,9 +939,6 @@ func TestBuildConfiguration(t *testing.T) {
952
939
Routes : map [types.NamespacedName ]* graph.Route {
953
940
{Namespace : "test" , Name : "hr-6" }: routeHR6 ,
954
941
},
955
- AcceptedHostnames : map [string ]struct {}{
956
- "foo.example.com" : {},
957
- },
958
942
},
959
943
"listener-443-1" : {
960
944
Source : listener443 ,
@@ -963,9 +947,6 @@ func TestBuildConfiguration(t *testing.T) {
963
947
Routes : map [types.NamespacedName ]* graph.Route {
964
948
{Namespace : "test" , Name : "https-hr-6" }: httpsRouteHR6 ,
965
949
},
966
- AcceptedHostnames : map [string ]struct {}{
967
- "foo.example.com" : {},
968
- },
969
950
},
970
951
},
971
952
},
@@ -1049,9 +1030,6 @@ func TestBuildConfiguration(t *testing.T) {
1049
1030
Routes : map [types.NamespacedName ]* graph.Route {
1050
1031
{Namespace : "test" , Name : "hr-7" }: routeHR7 ,
1051
1032
},
1052
- AcceptedHostnames : map [string ]struct {}{
1053
- "foo.example.com" : {},
1054
- },
1055
1033
},
1056
1034
},
1057
1035
},
@@ -1074,7 +1052,7 @@ func TestBuildConfiguration(t *testing.T) {
1074
1052
{
1075
1053
MatchIdx : 0 ,
1076
1054
RuleIdx : 1 ,
1077
- BackendGroup : hr7Groups [1 ],
1055
+ BackendGroup : expHR7Groups [1 ],
1078
1056
Source : hr7 ,
1079
1057
},
1080
1058
},
@@ -1086,7 +1064,7 @@ func TestBuildConfiguration(t *testing.T) {
1086
1064
{
1087
1065
MatchIdx : 0 ,
1088
1066
RuleIdx : 0 ,
1089
- BackendGroup : hr7Groups [0 ],
1067
+ BackendGroup : expHR7Groups [0 ],
1090
1068
Source : hr7 ,
1091
1069
},
1092
1070
},
@@ -1096,7 +1074,7 @@ func TestBuildConfiguration(t *testing.T) {
1096
1074
},
1097
1075
SSLServers : []VirtualServer {},
1098
1076
Upstreams : []Upstream {fooUpstream },
1099
- BackendGroups : []BackendGroup {hr7Groups [0 ], hr7Groups [1 ]},
1077
+ BackendGroups : []BackendGroup {expHR7Groups [0 ], expHR7Groups [1 ]},
1100
1078
},
1101
1079
msg : "duplicate paths with different types" ,
1102
1080
},
@@ -1116,9 +1094,6 @@ func TestBuildConfiguration(t *testing.T) {
1116
1094
Routes : map [types.NamespacedName ]* graph.Route {
1117
1095
{Namespace : "test" , Name : "https-hr-5" }: httpsRouteHR5 ,
1118
1096
},
1119
- AcceptedHostnames : map [string ]struct {}{
1120
- "example.com" : {},
1121
- },
1122
1097
},
1123
1098
"listener-443-1" : {
1124
1099
Source : listener443 ,
@@ -1127,9 +1102,6 @@ func TestBuildConfiguration(t *testing.T) {
1127
1102
Routes : map [types.NamespacedName ]* graph.Route {
1128
1103
{Namespace : "test" , Name : "https-hr-5" }: httpsRouteHR5 ,
1129
1104
},
1130
- AcceptedHostnames : map [string ]struct {}{
1131
- "example.com" : {},
1132
- },
1133
1105
},
1134
1106
},
1135
1107
},
0 commit comments