@@ -215,23 +215,26 @@ func TestBuildGateway(t *testing.T) {
215
215
createHTTPSListener := func (name , hostname string , port int , tls * v1beta1.GatewayTLSConfig ) v1beta1.Listener {
216
216
return createListener (name , hostname , port , v1beta1 .HTTPSProtocolType , tls )
217
217
}
218
+
218
219
// foo http listeners
219
220
foo80Listener1 := createHTTPListener ("foo-80-1" , "foo.example.com" , 80 )
220
221
foo80Listener2 := createHTTPListener ("foo-80-2" , "foo.example.com" , 80 )
221
222
foo8080Listener := createHTTPListener ("foo-8080" , "foo.example.com" , 8080 )
222
223
foo8081Listener := createHTTPListener ("foo-8081" , "foo.example.com" , 8081 )
224
+ foo443Listener := createHTTPListener ("foo-443" , "foo.example.com" , 443 )
223
225
224
226
// foo https listeners
225
- foo443Listener1 := createHTTPSListener ("foo-443-1" , "foo.example.com" , 443 , gatewayTLSConfig )
226
- foo443Listener2 := createHTTPSListener ("foo-443-2" , "foo.example.com" , 443 , gatewayTLSConfig )
227
- foo8443Listener := createHTTPSListener ("foo-8443" , "foo.example.com" , 8443 , gatewayTLSConfig )
227
+ foo80HTTPSListener := createHTTPSListener ("foo-80-https" , "foo.example.com" , 80 , gatewayTLSConfig )
228
+ foo443HTTPSListener1 := createHTTPSListener ("foo-443-https-1" , "foo.example.com" , 443 , gatewayTLSConfig )
229
+ foo443HTTPSListener2 := createHTTPSListener ("foo-443-https-2" , "foo.example.com" , 443 , gatewayTLSConfig )
230
+ foo8443HTTPSListener := createHTTPSListener ("foo-8443-https" , "foo.example.com" , 8443 , gatewayTLSConfig )
228
231
229
232
// bar http listener
230
233
bar80Listener := createHTTPListener ("bar-80" , "bar.example.com" , 80 )
231
234
232
235
// bar https listeners
233
- bar443Listener := createHTTPSListener ("bar-443" , "bar.example.com" , 443 , gatewayTLSConfig )
234
- bar8443Listener := createHTTPSListener ("bar-8443" , "bar.example.com" , 8443 , gatewayTLSConfig )
236
+ bar443HTTPSListener := createHTTPSListener ("bar-443-https " , "bar.example.com" , 443 , gatewayTLSConfig )
237
+ bar8443HTTPSListener := createHTTPSListener ("bar-8443-https " , "bar.example.com" , 8443 , gatewayTLSConfig )
235
238
236
239
// invalid listeners
237
240
invalidProtocolListener := createTCPListener ("invalid-protocol" , "bar.example.com" , 80 )
@@ -316,19 +319,21 @@ func TestBuildGateway(t *testing.T) {
316
319
name : "valid http listeners" ,
317
320
},
318
321
{
319
- gateway : createGateway (gatewayCfg {listeners : []v1beta1.Listener {foo443Listener1 , foo8443Listener }}),
322
+ gateway : createGateway (
323
+ gatewayCfg {listeners : []v1beta1.Listener {foo443HTTPSListener1 , foo8443HTTPSListener }},
324
+ ),
320
325
gatewayClass : validGC ,
321
326
expected : & Gateway {
322
327
Source : getLastCreatedGetaway (),
323
328
Listeners : map [string ]* Listener {
324
- "foo-443-1" : {
325
- Source : foo443Listener1 ,
329
+ "foo-443-https- 1" : {
330
+ Source : foo443HTTPSListener1 ,
326
331
Valid : true ,
327
332
Routes : map [types.NamespacedName ]* Route {},
328
333
SecretPath : secretPath ,
329
334
},
330
- "foo-8443" : {
331
- Source : foo8443Listener ,
335
+ "foo-8443-https " : {
336
+ Source : foo8443HTTPSListener ,
332
337
Valid : true ,
333
338
Routes : map [types.NamespacedName ]* Route {},
334
339
SecretPath : secretPath ,
@@ -479,11 +484,11 @@ func TestBuildGateway(t *testing.T) {
479
484
foo80Listener1 ,
480
485
foo8080Listener ,
481
486
foo8081Listener ,
482
- foo443Listener1 ,
483
- foo8443Listener ,
487
+ foo443HTTPSListener1 ,
488
+ foo8443HTTPSListener ,
484
489
bar80Listener ,
485
- bar443Listener ,
486
- bar8443Listener ,
490
+ bar443HTTPSListener ,
491
+ bar8443HTTPSListener ,
487
492
},
488
493
},
489
494
),
@@ -511,26 +516,26 @@ func TestBuildGateway(t *testing.T) {
511
516
Valid : true ,
512
517
Routes : map [types.NamespacedName ]* Route {},
513
518
},
514
- "foo-443-1" : {
515
- Source : foo443Listener1 ,
519
+ "foo-443-https- 1" : {
520
+ Source : foo443HTTPSListener1 ,
516
521
Valid : true ,
517
522
Routes : map [types.NamespacedName ]* Route {},
518
523
SecretPath : secretPath ,
519
524
},
520
- "foo-8443" : {
521
- Source : foo8443Listener ,
525
+ "foo-8443-https " : {
526
+ Source : foo8443HTTPSListener ,
522
527
Valid : true ,
523
528
Routes : map [types.NamespacedName ]* Route {},
524
529
SecretPath : secretPath ,
525
530
},
526
- "bar-443" : {
527
- Source : bar443Listener ,
531
+ "bar-443-https " : {
532
+ Source : bar443HTTPSListener ,
528
533
Valid : true ,
529
534
Routes : map [types.NamespacedName ]* Route {},
530
535
SecretPath : secretPath ,
531
536
},
532
- "bar-8443" : {
533
- Source : bar8443Listener ,
537
+ "bar-8443-https " : {
538
+ Source : bar8443HTTPSListener ,
534
539
Valid : true ,
535
540
Routes : map [types.NamespacedName ]* Route {},
536
541
SecretPath : secretPath ,
@@ -543,7 +548,12 @@ func TestBuildGateway(t *testing.T) {
543
548
{
544
549
gateway : createGateway (
545
550
gatewayCfg {
546
- listeners : []v1beta1.Listener {foo80Listener1 , foo80Listener2 , foo443Listener1 , foo443Listener2 },
551
+ listeners : []v1beta1.Listener {
552
+ foo80Listener1 ,
553
+ foo80Listener2 ,
554
+ foo443HTTPSListener1 ,
555
+ foo443HTTPSListener2 ,
556
+ },
547
557
},
548
558
),
549
559
gatewayClass : validGC ,
@@ -562,14 +572,61 @@ func TestBuildGateway(t *testing.T) {
562
572
Routes : map [types.NamespacedName ]* Route {},
563
573
Conditions : conditions .NewListenerConflictedHostname (conflictedHostnamesMsg ),
564
574
},
565
- "foo-443-1" : {
566
- Source : foo443Listener1 ,
575
+ "foo-443-https-1" : {
576
+ Source : foo443HTTPSListener1 ,
577
+ Valid : false ,
578
+ Routes : map [types.NamespacedName ]* Route {},
579
+ Conditions : conditions .NewListenerConflictedHostname (conflictedHostnamesMsg ),
580
+ SecretPath : "/etc/nginx/secrets/test_secret" ,
581
+ },
582
+ "foo-443-https-2" : {
583
+ Source : foo443HTTPSListener2 ,
567
584
Valid : false ,
568
585
Routes : map [types.NamespacedName ]* Route {},
569
586
Conditions : conditions .NewListenerConflictedHostname (conflictedHostnamesMsg ),
570
587
SecretPath : "/etc/nginx/secrets/test_secret" ,
571
- }, "foo-443-2" : {
572
- Source : foo443Listener2 ,
588
+ },
589
+ },
590
+ Valid : true ,
591
+ },
592
+ name : "collisions; same hostname, port, and protocol" ,
593
+ },
594
+ {
595
+ gateway : createGateway (
596
+ gatewayCfg {
597
+ listeners : []v1beta1.Listener {
598
+ foo80Listener1 ,
599
+ foo443Listener ,
600
+ foo80HTTPSListener ,
601
+ foo443HTTPSListener1 ,
602
+ },
603
+ },
604
+ ),
605
+ gatewayClass : validGC ,
606
+ expected : & Gateway {
607
+ Source : getLastCreatedGetaway (),
608
+ Listeners : map [string ]* Listener {
609
+ "foo-80-1" : {
610
+ Source : foo80Listener1 ,
611
+ Valid : false ,
612
+ Routes : map [types.NamespacedName ]* Route {},
613
+ Conditions : conditions .NewListenerConflictedHostname (conflictedHostnamesMsg ),
614
+ },
615
+ "foo-443" : {
616
+ Source : foo443Listener ,
617
+ Valid : false ,
618
+ Routes : map [types.NamespacedName ]* Route {},
619
+ Conditions : conditions .NewListenerConflictedHostname (conflictedHostnamesMsg ),
620
+ },
621
+ "foo-80-https" : {
622
+ Source : foo80HTTPSListener ,
623
+ Valid : false ,
624
+ Routes : map [types.NamespacedName ]* Route {},
625
+ Conditions : conditions .NewListenerConflictedHostname (conflictedHostnamesMsg ),
626
+ SecretPath : "/etc/nginx/secrets/test_secret" ,
627
+ },
628
+ "foo-443-https-1" : {
629
+ Source : foo443HTTPSListener1 ,
573
630
Valid : false ,
574
631
Routes : map [types.NamespacedName ]* Route {},
575
632
Conditions : conditions .NewListenerConflictedHostname (conflictedHostnamesMsg ),
@@ -578,12 +635,12 @@ func TestBuildGateway(t *testing.T) {
578
635
},
579
636
Valid : true ,
580
637
},
581
- name : "collisions" ,
638
+ name : "collisions; same hostname and port but different protocols " ,
582
639
},
583
640
{
584
641
gateway : createGateway (
585
642
gatewayCfg {
586
- listeners : []v1beta1.Listener {foo80Listener1 , foo443Listener1 },
643
+ listeners : []v1beta1.Listener {foo80Listener1 , foo443HTTPSListener1 },
587
644
addresses : []v1beta1.GatewayAddress {{}},
588
645
},
589
646
),
0 commit comments