@@ -286,10 +286,12 @@ func TestBuildGateway(t *testing.T) {
286
286
)
287
287
288
288
type gatewayCfg struct {
289
- name string
290
- ref * v1.LocalParametersReference
291
- listeners []v1.Listener
292
- addresses []v1.GatewaySpecAddress
289
+ ref * v1.LocalParametersReference
290
+ allowedListeners * v1.AllowedListeners
291
+ backendTLS * v1.GatewayBackendTLS
292
+ name string
293
+ listeners []v1.Listener
294
+ addresses []v1.GatewaySpecAddress
293
295
}
294
296
295
297
var lastCreatedGateway * v1.Gateway
@@ -304,6 +306,8 @@ func TestBuildGateway(t *testing.T) {
304
306
GatewayClassName : gcName ,
305
307
Listeners : cfg .listeners ,
306
308
Addresses : cfg .addresses ,
309
+ AllowedListeners : cfg .allowedListeners ,
310
+ BackendTLS : cfg .backendTLS ,
307
311
},
308
312
}
309
313
@@ -1513,6 +1517,103 @@ func TestBuildGateway(t *testing.T) {
1513
1517
},
1514
1518
},
1515
1519
},
1520
+ {
1521
+ name : "One unsupported field + supported fields (valid)" ,
1522
+ gateway : createGateway (gatewayCfg {
1523
+ name : "gateway-valid-np" ,
1524
+ listeners : []v1.Listener {foo80Listener1 },
1525
+ ref : validGwNpRef ,
1526
+ allowedListeners : & v1.AllowedListeners {},
1527
+ }),
1528
+ gatewayClass : validGCWithNp ,
1529
+ expected : map [types.NamespacedName ]* Gateway {
1530
+ {Namespace : validGwNp .Namespace , Name : "gateway-valid-np" }: {
1531
+ Source : getLastCreatedGateway (),
1532
+ Listeners : []* Listener {
1533
+ {
1534
+ Name : "foo-80-1" ,
1535
+ GatewayName : client .ObjectKeyFromObject (getLastCreatedGateway ()),
1536
+ Source : foo80Listener1 ,
1537
+ Valid : true ,
1538
+ Attachable : true ,
1539
+ Routes : map [RouteKey ]* L7Route {},
1540
+ L4Routes : map [L4RouteKey ]* L4Route {},
1541
+ SupportedKinds : supportedKindsForListeners ,
1542
+ },
1543
+ },
1544
+ DeploymentName : types.NamespacedName {
1545
+ Namespace : "test" ,
1546
+ Name : controller .CreateNginxResourceName ("gateway-valid-np" , gcName ),
1547
+ },
1548
+ Valid : true ,
1549
+ NginxProxy : & NginxProxy {
1550
+ Source : validGwNp ,
1551
+ Valid : true ,
1552
+ },
1553
+ EffectiveNginxProxy : & EffectiveNginxProxy {
1554
+ Logging : & ngfAPIv1alpha2.NginxLogging {
1555
+ ErrorLevel : helpers .GetPointer (ngfAPIv1alpha2 .NginxLogLevelError ),
1556
+ },
1557
+ IPFamily : helpers .GetPointer (ngfAPIv1alpha2 .Dual ),
1558
+ Metrics : & ngfAPIv1alpha2.Metrics {
1559
+ Disable : helpers .GetPointer (false ),
1560
+ Port : helpers .GetPointer (int32 (90 )),
1561
+ },
1562
+ },
1563
+ Conditions : []conditions.Condition {
1564
+ conditions .NewGatewayAcceptedUnsupportedField ("AllowedListeners" ),
1565
+ conditions .NewGatewayResolvedRefs (),
1566
+ },
1567
+ },
1568
+ },
1569
+ },
1570
+ {
1571
+ name : "One unsupported field + NewGatewayRefInvalid (invalid)" ,
1572
+ gateway : createGateway (gatewayCfg {
1573
+ name : "gateway-valid-np" ,
1574
+ listeners : []v1.Listener {foo80Listener1 },
1575
+ ref : & v1.LocalParametersReference {
1576
+ Kind : "wrong-kind" , // Invalid reference
1577
+ Name : "invalid-ref" ,
1578
+ },
1579
+ backendTLS : & v1.GatewayBackendTLS {},
1580
+ }),
1581
+ gatewayClass : validGCWithNp ,
1582
+ expected : map [types.NamespacedName ]* Gateway {
1583
+ {Namespace : validGwNp .Namespace , Name : "gateway-valid-np" }: {
1584
+ Source : getLastCreatedGateway (),
1585
+ Listeners : []* Listener {
1586
+ {
1587
+ Name : "foo-80-1" ,
1588
+ GatewayName : client .ObjectKeyFromObject (getLastCreatedGateway ()),
1589
+ Source : foo80Listener1 ,
1590
+ Valid : true ,
1591
+ Attachable : true ,
1592
+ Routes : map [RouteKey ]* L7Route {},
1593
+ L4Routes : map [L4RouteKey ]* L4Route {},
1594
+ SupportedKinds : supportedKindsForListeners ,
1595
+ },
1596
+ },
1597
+ DeploymentName : types.NamespacedName {
1598
+ Namespace : "test" ,
1599
+ Name : controller .CreateNginxResourceName ("gateway-valid-np" , gcName ),
1600
+ },
1601
+ Valid : true ,
1602
+ EffectiveNginxProxy : & EffectiveNginxProxy {
1603
+ IPFamily : helpers .GetPointer (ngfAPIv1alpha2 .Dual ),
1604
+ },
1605
+ Conditions : []conditions.Condition {
1606
+ conditions .NewGatewayAcceptedUnsupportedField ("BackendTLS" ),
1607
+ conditions .NewGatewayRefInvalid (
1608
+ "spec.infrastructure.parametersRef.kind: Unsupported value: \" wrong-kind\" : supported values: \" NginxProxy\" " ,
1609
+ ),
1610
+ conditions .NewGatewayInvalidParameters (
1611
+ "spec.infrastructure.parametersRef.kind: Unsupported value: \" wrong-kind\" : supported values: \" NginxProxy\" " ,
1612
+ ),
1613
+ },
1614
+ },
1615
+ },
1616
+ },
1516
1617
}
1517
1618
1518
1619
secretResolver := newSecretResolver (
@@ -1821,3 +1922,55 @@ func TestGetReferencedSnippetsFilters(t *testing.T) {
1821
1922
emptyFilterResult := gw .GetReferencedSnippetsFilters (routes , map [types.NamespacedName ]* SnippetsFilter {})
1822
1923
g .Expect (emptyFilterResult ).To (BeEmpty ())
1823
1924
}
1925
+
1926
+ func TestValidateUnsupportedGatewayFields (t * testing.T ) {
1927
+ t .Parallel ()
1928
+
1929
+ tests := []struct {
1930
+ name string
1931
+ gateway * v1.Gateway
1932
+ expectedConds []conditions.Condition
1933
+ }{
1934
+ {
1935
+ name : "No unsupported fields" ,
1936
+ gateway : & v1.Gateway {
1937
+ Spec : v1.GatewaySpec {},
1938
+ },
1939
+ expectedConds : nil ,
1940
+ },
1941
+ {
1942
+ name : "One unsupported field: AllowedListeners" ,
1943
+ gateway : & v1.Gateway {
1944
+ Spec : v1.GatewaySpec {
1945
+ AllowedListeners : & v1.AllowedListeners {},
1946
+ },
1947
+ },
1948
+ expectedConds : []conditions.Condition {
1949
+ conditions .NewGatewayAcceptedUnsupportedField ("AllowedListeners" ),
1950
+ },
1951
+ },
1952
+ {
1953
+ name : "Multiple unsupported fields: AllowedListeners and BackendTLS" ,
1954
+ gateway : & v1.Gateway {
1955
+ Spec : v1.GatewaySpec {
1956
+ AllowedListeners : & v1.AllowedListeners {},
1957
+ BackendTLS : & v1.GatewayBackendTLS {},
1958
+ },
1959
+ },
1960
+ expectedConds : []conditions.Condition {
1961
+ conditions .NewGatewayAcceptedUnsupportedField ("AllowedListeners" ),
1962
+ conditions .NewGatewayAcceptedUnsupportedField ("BackendTLS" ),
1963
+ },
1964
+ },
1965
+ }
1966
+
1967
+ for _ , test := range tests {
1968
+ t .Run (test .name , func (t * testing.T ) {
1969
+ t .Parallel ()
1970
+ g := NewWithT (t )
1971
+
1972
+ conds := validateUnsupportedGatewayFields (test .gateway )
1973
+ g .Expect (conds ).To (Equal (test .expectedConds ))
1974
+ })
1975
+ }
1976
+ }
0 commit comments