@@ -18,7 +18,6 @@ import (
18
18
"github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers"
19
19
"github.com/nginxinc/nginx-kubernetes-gateway/internal/manager/index"
20
20
"github.com/nginxinc/nginx-kubernetes-gateway/internal/state"
21
- "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/graph"
22
21
"github.com/nginxinc/nginx-kubernetes-gateway/internal/state/relationship"
23
22
"github.com/nginxinc/nginx-kubernetes-gateway/internal/state/relationship/relationshipfakes"
24
23
"github.com/nginxinc/nginx-kubernetes-gateway/internal/state/secrets/secretsfakes"
@@ -221,9 +220,9 @@ var _ = Describe("ChangeProcessor", func() {
221
220
222
221
Describe ("Process gateway resources" , Ordered , func () {
223
222
var (
224
- gcUpdated * v1beta1.GatewayClass
225
- hr1 , hr1Updated * v1beta1.HTTPRoute
226
- gw1 , gw1Updated * v1beta1.Gateway
223
+ gcUpdated * v1beta1.GatewayClass
224
+ hr1 , hr1Updated , hr2 * v1beta1.HTTPRoute
225
+ gw1 , gw1Updated , gw2 * v1beta1.Gateway
227
226
)
228
227
BeforeAll (func () {
229
228
gcUpdated = gc .DeepCopy ()
@@ -234,10 +233,14 @@ var _ = Describe("ChangeProcessor", func() {
234
233
hr1Updated = hr1 .DeepCopy ()
235
234
hr1Updated .Generation ++
236
235
236
+ hr2 = createRoute ("hr-2" , "gateway-2" , "bar.example.com" )
237
+
237
238
gw1 = createGatewayWithTLSListener ("gateway-1" )
238
239
239
240
gw1Updated = gw1 .DeepCopy ()
240
241
gw1Updated .Generation ++
242
+
243
+ gw2 = createGatewayWithTLSListener ("gateway-2" )
241
244
})
242
245
243
246
When ("no upsert has occurred" , func () {
@@ -247,15 +250,36 @@ var _ = Describe("ChangeProcessor", func() {
247
250
Expect (graphCfg ).To (BeNil ())
248
251
})
249
252
})
250
- When ("upsert has occurred" , func () {
251
- It ("returns populated graph" , func () {
252
- processor .CaptureUpsertChange (hr1 )
253
- processor .CaptureUpsertChange (gw1 )
253
+ When ("GatewayClass doesn't exist" , func () {
254
+ When ("Gateways don't exist" , func () {
255
+ When ("the first HTTPRoute is upserted" , func () {
256
+ It ("returns empty graph" , func () {
257
+ processor .CaptureUpsertChange (hr1 )
258
+
259
+ changed , graphCfg := processor .Process ()
260
+ Expect (changed ).To (BeTrue ())
261
+ Expect (graphCfg .Routes ).To (BeNil ())
262
+ })
263
+ })
264
+ When ("the first Gateway is upserted" , func () {
265
+ It ("returns populated graph" , func () {
266
+ processor .CaptureUpsertChange (gw1 )
267
+
268
+ changed , graphCfg := processor .Process ()
269
+ Expect (changed ).To (BeTrue ())
270
+ Expect (graphCfg .Gateway ).ToNot (BeNil ())
271
+ Expect (graphCfg .Routes ).To (HaveLen (1 ))
272
+ })
273
+ })
274
+ })
275
+ })
276
+ When ("the GatewayClass is upserted" , func () {
277
+ It ("returns updated graph" , func () {
254
278
processor .CaptureUpsertChange (gc )
255
279
256
280
changed , graphCfg := processor .Process ()
257
281
Expect (changed ).To (BeTrue ())
258
- Expect (graphCfg ).ToNot (BeNil ())
282
+ Expect (graphCfg . GatewayClass ).ToNot (BeNil ())
259
283
})
260
284
})
261
285
When ("the first HTTPRoute without a generation changed is processed" , func () {
@@ -275,7 +299,7 @@ var _ = Describe("ChangeProcessor", func() {
275
299
276
300
changed , graphCfg := processor .Process ()
277
301
Expect (changed ).To (BeTrue ())
278
- Expect (graphCfg ). ToNot ( BeNil ( ))
302
+ Expect (graphCfg . Routes ). To ( HaveLen ( 1 ))
279
303
},
280
304
)
281
305
})
@@ -296,7 +320,7 @@ var _ = Describe("ChangeProcessor", func() {
296
320
297
321
changed , graphCfg := processor .Process ()
298
322
Expect (changed ).To (BeTrue ())
299
- Expect (graphCfg ).ToNot (BeNil ())
323
+ Expect (graphCfg . Gateway ).ToNot (BeNil ())
300
324
})
301
325
})
302
326
When ("the GatewayClass update without generation change is processed" , func () {
@@ -316,7 +340,7 @@ var _ = Describe("ChangeProcessor", func() {
316
340
317
341
changed , graphCfg := processor .Process ()
318
342
Expect (changed ).To (BeTrue ())
319
- Expect (graphCfg ).ToNot (BeNil ())
343
+ Expect (graphCfg . GatewayClass ).ToNot (BeNil ())
320
344
})
321
345
})
322
346
When ("no changes are captured" , func () {
@@ -327,26 +351,83 @@ var _ = Describe("ChangeProcessor", func() {
327
351
Expect (graphCfg ).To (BeNil ())
328
352
})
329
353
})
330
- When ("resources are deleted" , func () {
331
- It ("returns empty graph" , func () {
354
+ When ("the second Gateway is upserted" , func () {
355
+ It ("returns populated graph using first gateway" , func () {
356
+ processor .CaptureUpsertChange (gw2 )
357
+
358
+ changed , graphCfg := processor .Process ()
359
+ Expect (changed ).To (BeTrue ())
360
+ Expect (graphCfg .Gateway .Source .Name ).To (Equal (gw1 .Name ))
361
+ })
362
+ })
363
+ When ("the second HTTPRoute is upserted" , func () {
364
+ It ("returns populated graph" , func () {
365
+ processor .CaptureUpsertChange (hr2 )
366
+
367
+ changed , graphCfg := processor .Process ()
368
+ Expect (changed ).To (BeTrue ())
369
+ Expect (graphCfg .Routes ).To (HaveLen (2 ))
370
+ })
371
+ })
372
+ When ("the first Gateway is deleted" , func () {
373
+ It ("returns updated graph" , func () {
374
+ processor .CaptureDeleteChange (
375
+ & v1beta1.Gateway {},
376
+ types.NamespacedName {Namespace : "test" , Name : "gateway-1" },
377
+ )
378
+
379
+ changed , graphCfg := processor .Process ()
380
+ Expect (changed ).To (BeTrue ())
381
+ Expect (graphCfg .Gateway .Source .Name ).To (Equal (gw2 .Name ))
382
+ Expect (graphCfg .Routes ).To (HaveLen (1 ))
383
+ })
384
+ })
385
+ When ("the second HTTPRoute is deleted" , func () {
386
+ It ("returns updated graph" , func () {
387
+ processor .CaptureDeleteChange (
388
+ & v1beta1.HTTPRoute {},
389
+ types.NamespacedName {Namespace : "test" , Name : "hr-2" },
390
+ )
391
+
392
+ changed , graphCfg := processor .Process ()
393
+ Expect (changed ).To (BeTrue ())
394
+ Expect (graphCfg .Routes ).To (HaveLen (0 ))
395
+ })
396
+ })
397
+ When ("the GatewayClass is deleted" , func () {
398
+ It ("returns updated graph" , func () {
332
399
processor .CaptureDeleteChange (
333
400
& v1beta1.GatewayClass {},
334
401
types.NamespacedName {Name : gcName },
335
402
)
403
+
404
+ changed , graphCfg := processor .Process ()
405
+ Expect (changed ).To (BeTrue ())
406
+ Expect (graphCfg .GatewayClass ).To (BeNil ())
407
+ })
408
+ })
409
+ When ("the second Gateway is deleted" , func () {
410
+ It ("returns updated graph" , func () {
336
411
processor .CaptureDeleteChange (
337
412
& v1beta1.Gateway {},
338
- types.NamespacedName {Namespace : "test" , Name : "gateway-1 " },
413
+ types.NamespacedName {Namespace : "test" , Name : "gateway-2 " },
339
414
)
415
+
416
+ changed , graphCfg := processor .Process ()
417
+ Expect (changed ).To (BeTrue ())
418
+ Expect (graphCfg .Gateway ).To (BeNil ())
419
+ })
420
+ })
421
+ When ("the first HTTPRoute is deleted" , func () {
422
+ It ("returns updated graph" , func () {
340
423
processor .CaptureDeleteChange (
341
424
& v1beta1.HTTPRoute {},
342
425
types.NamespacedName {Namespace : "test" , Name : "hr-1" },
343
426
)
344
427
345
- emptyGraph := & graph.Graph {}
346
-
347
428
changed , graphCfg := processor .Process ()
348
429
Expect (changed ).To (BeTrue ())
349
- Expect (helpers . Diff ( emptyGraph , graphCfg )) .To (BeEmpty ())
430
+ Expect (graphCfg . Routes ) .To (BeNil ())
350
431
})
351
432
})
352
433
})
@@ -685,9 +766,6 @@ var _ = Describe("ChangeProcessor", func() {
685
766
})
686
767
687
768
Describe ("Ensuring non-changing changes don't override previously changing changes" , func () {
688
- // Note: in these tests, we deliberately don't fully inspect the returned configuration and statuses
689
- // -- this is done in 'Normal cases of processing changes'
690
-
691
769
var (
692
770
processor * state.ChangeProcessorImpl
693
771
fakeRelationshipCapturer * relationshipfakes.FakeCapturer
0 commit comments