@@ -66,9 +66,7 @@ func getExpectedConfiguration() Configuration {
66
66
Logging : Logging {
67
67
ErrorLevel : defaultErrorLogLevel ,
68
68
},
69
- NginxPlus : NginxPlus {
70
- AllowedAddresses : []string {"127.0.0.1" },
71
- },
69
+ NginxPlus : NginxPlus {},
72
70
}
73
71
}
74
72
@@ -870,7 +868,7 @@ func TestBuildConfiguration(t *testing.T) {
870
868
871
869
defaultConfig := Configuration {
872
870
Logging : Logging {ErrorLevel : defaultErrorLogLevel },
873
- NginxPlus : NginxPlus {AllowedAddresses : [] string { "127.0.0.1" } },
871
+ NginxPlus : NginxPlus {},
874
872
}
875
873
876
874
tests := []struct {
@@ -1559,36 +1557,14 @@ func TestBuildConfiguration(t *testing.T) {
1559
1557
{
1560
1558
graph : getModifiedGraph (func (g * graph.Graph ) * graph.Graph {
1561
1559
g .GatewayClass .Valid = false
1562
- g .Gateway .Listeners = append (g .Gateway .Listeners , & graph.Listener {
1563
- Name : "listener-80-1" ,
1564
- Source : listener80 ,
1565
- Valid : true ,
1566
- Routes : map [graph.RouteKey ]* graph.L7Route {
1567
- graph .CreateRouteKey (hr1 ): routeHR1 ,
1568
- },
1569
- })
1570
- g .Routes = map [graph.RouteKey ]* graph.L7Route {
1571
- graph .CreateRouteKey (hr1 ): routeHR1 ,
1572
- }
1573
1560
return g
1574
1561
}),
1575
1562
expConf : defaultConfig ,
1576
1563
msg : "invalid gatewayclass" ,
1577
1564
},
1578
1565
{
1579
1566
graph : getModifiedGraph (func (g * graph.Graph ) * graph.Graph {
1580
- g .GatewayClass .Valid = false
1581
- g .Gateway .Listeners = append (g .Gateway .Listeners , & graph.Listener {
1582
- Name : "listener-80-1" ,
1583
- Source : listener80 ,
1584
- Valid : true ,
1585
- Routes : map [graph.RouteKey ]* graph.L7Route {
1586
- graph .CreateRouteKey (hr1 ): routeHR1 ,
1587
- },
1588
- })
1589
- g .Routes = map [graph.RouteKey ]* graph.L7Route {
1590
- graph .CreateRouteKey (hr1 ): routeHR1 ,
1591
- }
1567
+ g .GatewayClass = nil
1592
1568
return g
1593
1569
}),
1594
1570
expConf : defaultConfig ,
@@ -2374,6 +2350,100 @@ func TestBuildConfiguration(t *testing.T) {
2374
2350
}),
2375
2351
msg : "SnippetsFilters with main and http snippet" ,
2376
2352
},
2353
+ {
2354
+ graph : getModifiedGraph (func (g * graph.Graph ) * graph.Graph {
2355
+ g .Gateway .Source .ObjectMeta = metav1.ObjectMeta {
2356
+ Name : "gw" ,
2357
+ Namespace : "ns" ,
2358
+ }
2359
+ g .Gateway .Listeners = append (g .Gateway .Listeners , & graph.Listener {
2360
+ Name : "listener-80-1" ,
2361
+ Source : listener80 ,
2362
+ Valid : true ,
2363
+ Routes : map [graph.RouteKey ]* graph.L7Route {},
2364
+ })
2365
+ g .NginxProxy = & graph.NginxProxy {
2366
+ Valid : true ,
2367
+ Source : & ngfAPIv1alpha1.NginxProxy {
2368
+ Spec : ngfAPIv1alpha1.NginxProxySpec {
2369
+ NginxPlus : & ngfAPIv1alpha1.NginxPlus {
2370
+ AllowedAddresses : []ngfAPIv1alpha1.NginxPlusAllowAddress {
2371
+ {Type : ngfAPIv1alpha1 .NginxPlusAllowIPAddressType , Value : "127.0.0.3" },
2372
+ {Type : ngfAPIv1alpha1 .NginxPlusAllowIPAddressType , Value : "25.0.0.3" },
2373
+ },
2374
+ },
2375
+ },
2376
+ },
2377
+ }
2378
+ return g
2379
+ }),
2380
+ expConf : getModifiedExpectedConfiguration (func (conf Configuration ) Configuration {
2381
+ conf .SSLServers = []VirtualServer {}
2382
+ conf .SSLKeyPairs = map [SSLKeyPairID ]SSLKeyPair {}
2383
+ return conf
2384
+ }),
2385
+ msg : "NginxProxy with NginxPlus allowed addresses configured but running on nginx oss" ,
2386
+ },
2387
+ }
2388
+
2389
+ for _ , test := range tests {
2390
+ t .Run (test .msg , func (t * testing.T ) {
2391
+ t .Parallel ()
2392
+ g := NewWithT (t )
2393
+
2394
+ result := BuildConfiguration (
2395
+ context .TODO (),
2396
+ test .graph ,
2397
+ fakeResolver ,
2398
+ 1 ,
2399
+ false ,
2400
+ )
2401
+
2402
+ g .Expect (result .BackendGroups ).To (ConsistOf (test .expConf .BackendGroups ))
2403
+ g .Expect (result .Upstreams ).To (ConsistOf (test .expConf .Upstreams ))
2404
+ g .Expect (result .HTTPServers ).To (ConsistOf (test .expConf .HTTPServers ))
2405
+ g .Expect (result .SSLServers ).To (ConsistOf (test .expConf .SSLServers ))
2406
+ g .Expect (result .TLSPassthroughServers ).To (ConsistOf (test .expConf .TLSPassthroughServers ))
2407
+ g .Expect (result .SSLKeyPairs ).To (Equal (test .expConf .SSLKeyPairs ))
2408
+ g .Expect (result .Version ).To (Equal (1 ))
2409
+ g .Expect (result .CertBundles ).To (Equal (test .expConf .CertBundles ))
2410
+ g .Expect (result .Telemetry ).To (Equal (test .expConf .Telemetry ))
2411
+ g .Expect (result .BaseHTTPConfig ).To (Equal (test .expConf .BaseHTTPConfig ))
2412
+ g .Expect (result .Logging ).To (Equal (test .expConf .Logging ))
2413
+ g .Expect (result .NginxPlus ).To (Equal (test .expConf .NginxPlus ))
2414
+ })
2415
+ }
2416
+ }
2417
+
2418
+ func TestBuildConfiguration_Plus (t * testing.T ) {
2419
+ t .Parallel ()
2420
+ fooEndpoints := []resolver.Endpoint {
2421
+ {
2422
+ Address : "10.0.0.0" ,
2423
+ Port : 8080 ,
2424
+ },
2425
+ }
2426
+
2427
+ fakeResolver := & resolverfakes.FakeServiceResolver {}
2428
+ fakeResolver .ResolveReturns (fooEndpoints , nil )
2429
+
2430
+ listener80 := v1.Listener {
2431
+ Name : "listener-80-1" ,
2432
+ Hostname : nil ,
2433
+ Port : 80 ,
2434
+ Protocol : v1 .HTTPProtocolType ,
2435
+ }
2436
+
2437
+ defaultPlusConfig := Configuration {
2438
+ Logging : Logging {ErrorLevel : defaultErrorLogLevel },
2439
+ NginxPlus : NginxPlus {AllowedAddresses : []string {"127.0.0.1" }},
2440
+ }
2441
+
2442
+ tests := []struct {
2443
+ graph * graph.Graph
2444
+ msg string
2445
+ expConf Configuration
2446
+ }{
2377
2447
{
2378
2448
graph : getModifiedGraph (func (g * graph.Graph ) * graph.Graph {
2379
2449
g .Gateway .Source .ObjectMeta = metav1.ObjectMeta {
@@ -2409,6 +2479,30 @@ func TestBuildConfiguration(t *testing.T) {
2409
2479
}),
2410
2480
msg : "NginxProxy with NginxPlus allowed addresses configured" ,
2411
2481
},
2482
+ {
2483
+ graph : getModifiedGraph (func (g * graph.Graph ) * graph.Graph {
2484
+ g .GatewayClass .Valid = false
2485
+ return g
2486
+ }),
2487
+ expConf : defaultPlusConfig ,
2488
+ msg : "invalid gatewayclass" ,
2489
+ },
2490
+ {
2491
+ graph : getModifiedGraph (func (g * graph.Graph ) * graph.Graph {
2492
+ g .GatewayClass = nil
2493
+ return g
2494
+ }),
2495
+ expConf : defaultPlusConfig ,
2496
+ msg : "missing gatewayclass" ,
2497
+ },
2498
+ {
2499
+ graph : getModifiedGraph (func (g * graph.Graph ) * graph.Graph {
2500
+ g .Gateway = nil
2501
+ return g
2502
+ }),
2503
+ expConf : defaultPlusConfig ,
2504
+ msg : "missing gateway" ,
2505
+ },
2412
2506
}
2413
2507
2414
2508
for _ , test := range tests {
@@ -2421,6 +2515,7 @@ func TestBuildConfiguration(t *testing.T) {
2421
2515
test .graph ,
2422
2516
fakeResolver ,
2423
2517
1 ,
2518
+ true ,
2424
2519
)
2425
2520
2426
2521
g .Expect (result .BackendGroups ).To (ConsistOf (test .expConf .BackendGroups ))
0 commit comments