@@ -218,15 +218,13 @@ func TestBuildGateway(t *testing.T) {
218
218
219
219
// foo http listeners
220
220
foo80Listener1 := createHTTPListener ("foo-80-1" , "foo.example.com" , 80 )
221
- foo80Listener2 := createHTTPListener ("foo-80-2" , "foo.example.com" , 80 )
222
221
foo8080Listener := createHTTPListener ("foo-8080" , "foo.example.com" , 8080 )
223
222
foo8081Listener := createHTTPListener ("foo-8081" , "foo.example.com" , 8081 )
224
223
foo443Listener := createHTTPListener ("foo-443" , "foo.example.com" , 443 )
225
224
226
225
// foo https listeners
227
226
foo80HTTPSListener := createHTTPSListener ("foo-80-https" , "foo.example.com" , 80 , gatewayTLSConfig )
228
227
foo443HTTPSListener1 := createHTTPSListener ("foo-443-https-1" , "foo.example.com" , 443 , gatewayTLSConfig )
229
- foo443HTTPSListener2 := createHTTPSListener ("foo-443-https-2" , "foo.example.com" , 443 , gatewayTLSConfig )
230
228
foo8443HTTPSListener := createHTTPSListener ("foo-8443-https" , "foo.example.com" , 8443 , gatewayTLSConfig )
231
229
232
230
// bar http listener
@@ -255,8 +253,11 @@ func TestBuildGateway(t *testing.T) {
255
253
"with an alphanumeric character (e.g. 'example.com', regex used for validation is " +
256
254
`'[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')`
257
255
258
- conflictedHostnamesMsg = `Multiple listeners for the same port use the same hostname "foo.example.com"; ` +
259
- "ensure only one listener uses that hostname"
256
+ conflict80PortMsg = "Multiple listeners for the same port 80 specify different protocols; " +
257
+ "ensure only one protocol per port"
258
+
259
+ conflict443PortMsg = "Multiple listeners for the same port 443 specify different protocols; " +
260
+ "ensure only one protocol per port"
260
261
261
262
secretPath = "/etc/nginx/secrets/test_secret"
262
263
)
@@ -550,9 +551,11 @@ func TestBuildGateway(t *testing.T) {
550
551
gatewayCfg {
551
552
listeners : []v1beta1.Listener {
552
553
foo80Listener1 ,
553
- foo80Listener2 ,
554
+ bar80Listener ,
555
+ foo443Listener ,
556
+ foo80HTTPSListener ,
554
557
foo443HTTPSListener1 ,
555
- foo443HTTPSListener2 ,
558
+ bar443HTTPSListener ,
556
559
},
557
560
},
558
561
),
@@ -564,78 +567,45 @@ func TestBuildGateway(t *testing.T) {
564
567
Source : foo80Listener1 ,
565
568
Valid : false ,
566
569
Routes : map [types.NamespacedName ]* Route {},
567
- Conditions : conditions .NewListenerConflictedHostname (conflictedHostnamesMsg ),
568
- },
569
- "foo-80-2" : {
570
- Source : foo80Listener2 ,
571
- Valid : false ,
572
- Routes : map [types.NamespacedName ]* Route {},
573
- Conditions : conditions .NewListenerConflictedHostname (conflictedHostnamesMsg ),
574
- },
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 ,
584
- Valid : false ,
585
- Routes : map [types.NamespacedName ]* Route {},
586
- Conditions : conditions .NewListenerConflictedHostname (conflictedHostnamesMsg ),
587
- SecretPath : "/etc/nginx/secrets/test_secret" ,
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 ,
570
+ Conditions : conditions .NewListenerProtocolConflict (conflict80PortMsg ),
602
571
},
603
- },
604
- ),
605
- gatewayClass : validGC ,
606
- expected : & Gateway {
607
- Source : getLastCreatedGetaway (),
608
- Listeners : map [string ]* Listener {
609
- "foo-80-1" : {
610
- Source : foo80Listener1 ,
572
+ "bar-80" : {
573
+ Source : bar80Listener ,
611
574
Valid : false ,
612
575
Routes : map [types.NamespacedName ]* Route {},
613
- Conditions : conditions .NewListenerConflictedHostname ( conflictedHostnamesMsg ),
576
+ Conditions : conditions .NewListenerProtocolConflict ( conflict80PortMsg ),
614
577
},
615
578
"foo-443" : {
616
579
Source : foo443Listener ,
617
580
Valid : false ,
618
581
Routes : map [types.NamespacedName ]* Route {},
619
- Conditions : conditions .NewListenerConflictedHostname ( conflictedHostnamesMsg ),
582
+ Conditions : conditions .NewListenerProtocolConflict ( conflict443PortMsg ),
620
583
},
621
584
"foo-80-https" : {
622
585
Source : foo80HTTPSListener ,
623
586
Valid : false ,
624
587
Routes : map [types.NamespacedName ]* Route {},
625
- Conditions : conditions .NewListenerConflictedHostname ( conflictedHostnamesMsg ),
588
+ Conditions : conditions .NewListenerProtocolConflict ( conflict80PortMsg ),
626
589
SecretPath : "/etc/nginx/secrets/test_secret" ,
627
590
},
628
591
"foo-443-https-1" : {
629
592
Source : foo443HTTPSListener1 ,
630
593
Valid : false ,
631
594
Routes : map [types.NamespacedName ]* Route {},
632
- Conditions : conditions .NewListenerConflictedHostname (conflictedHostnamesMsg ),
595
+ Conditions : conditions .NewListenerProtocolConflict (conflict443PortMsg ),
596
+ SecretPath : "/etc/nginx/secrets/test_secret" ,
597
+ },
598
+ "bar-443-https" : {
599
+ Source : bar443HTTPSListener ,
600
+ Valid : false ,
601
+ Routes : map [types.NamespacedName ]* Route {},
602
+ Conditions : conditions .NewListenerProtocolConflict (conflict443PortMsg ),
633
603
SecretPath : "/etc/nginx/secrets/test_secret" ,
634
604
},
635
605
},
636
606
Valid : true ,
637
607
},
638
- name : "collisions; same hostname and port but different protocols " ,
608
+ name : "port/protocol collisions " ,
639
609
},
640
610
{
641
611
gateway : createGateway (
0 commit comments