@@ -2,6 +2,7 @@ package state_test
2
2
3
3
import (
4
4
"context"
5
+ "sort"
5
6
6
7
. "github.com/onsi/ginkgo/v2"
7
8
. "github.com/onsi/gomega"
@@ -17,6 +18,7 @@ import (
17
18
"github.com/nginxinc/nginx-kubernetes-gateway/internal/helpers"
18
19
"github.com/nginxinc/nginx-kubernetes-gateway/internal/manager/index"
19
20
"github.com/nginxinc/nginx-kubernetes-gateway/internal/state"
21
+ "github.com/nginxinc/nginx-kubernetes-gateway/internal/state/conditions"
20
22
"github.com/nginxinc/nginx-kubernetes-gateway/internal/state/relationship"
21
23
"github.com/nginxinc/nginx-kubernetes-gateway/internal/state/relationship/relationshipfakes"
22
24
"github.com/nginxinc/nginx-kubernetes-gateway/internal/state/statefakes"
@@ -228,6 +230,24 @@ var _ = Describe("ChangeProcessor", func() {
228
230
229
231
gw2 = createGatewayWithTLSListener ("gateway-2" )
230
232
})
233
+
234
+ assertStatuses := func (expected , result state.Statuses ) {
235
+ sortConditions := func (statuses state.HTTPRouteStatuses ) {
236
+ for _ , status := range statuses {
237
+ for _ , ps := range status .ParentStatuses {
238
+ sort .Slice (ps .Conditions , func (i , j int ) bool {
239
+ return ps .Conditions [i ].Type < ps .Conditions [j ].Type
240
+ })
241
+ }
242
+ }
243
+ }
244
+
245
+ sortConditions (expected .HTTPRouteStatuses )
246
+ sortConditions (result .HTTPRouteStatuses )
247
+
248
+ ExpectWithOffset (1 , helpers .Diff (expected , result )).To (BeEmpty ())
249
+ }
250
+
231
251
When ("no upsert has occurred" , func () {
232
252
It ("returns empty configuration and statuses" , func () {
233
253
changed , conf , statuses := processor .Process (context .TODO ())
@@ -279,8 +299,18 @@ var _ = Describe("ChangeProcessor", func() {
279
299
{Namespace : "test" , Name : "hr-1" }: {
280
300
ObservedGeneration : hr1 .Generation ,
281
301
ParentStatuses : map [string ]state.ParentStatus {
282
- "listener-80-1" : {Attached : false },
283
- "listener-443-1" : {Attached : false },
302
+ "listener-80-1" : {
303
+ Conditions : append (
304
+ conditions .NewDefaultRouteConditions (),
305
+ conditions .NewRouteTODO ("GatewayClass is invalid or doesn't exist" ),
306
+ ),
307
+ },
308
+ "listener-443-1" : {
309
+ Conditions : append (
310
+ conditions .NewDefaultRouteConditions (),
311
+ conditions .NewRouteTODO ("GatewayClass is invalid or doesn't exist" ),
312
+ ),
313
+ },
284
314
},
285
315
},
286
316
},
@@ -289,7 +319,7 @@ var _ = Describe("ChangeProcessor", func() {
289
319
changed , conf , statuses := processor .Process (context .TODO ())
290
320
Expect (changed ).To (BeTrue ())
291
321
Expect (helpers .Diff (expectedConf , conf )).To (BeEmpty ())
292
- Expect ( helpers . Diff ( expectedStatuses , statuses )). To ( BeEmpty () )
322
+ assertStatuses ( expectedStatuses , statuses )
293
323
})
294
324
})
295
325
})
@@ -367,8 +397,12 @@ var _ = Describe("ChangeProcessor", func() {
367
397
{Namespace : "test" , Name : "hr-1" }: {
368
398
ObservedGeneration : hr1 .Generation ,
369
399
ParentStatuses : map [string ]state.ParentStatus {
370
- "listener-80-1" : {Attached : true },
371
- "listener-443-1" : {Attached : true },
400
+ "listener-80-1" : {
401
+ Conditions : conditions .NewDefaultRouteConditions (),
402
+ },
403
+ "listener-443-1" : {
404
+ Conditions : conditions .NewDefaultRouteConditions (),
405
+ },
372
406
},
373
407
},
374
408
},
@@ -377,7 +411,7 @@ var _ = Describe("ChangeProcessor", func() {
377
411
changed , conf , statuses := processor .Process (context .TODO ())
378
412
Expect (changed ).To (BeTrue ())
379
413
Expect (helpers .Diff (expectedConf , conf )).To (BeEmpty ())
380
- Expect ( helpers . Diff ( expectedStatuses , statuses )). To ( BeEmpty () )
414
+ assertStatuses ( expectedStatuses , statuses )
381
415
})
382
416
})
383
417
When ("the first HTTPRoute without a generation changed is processed" , func () {
@@ -465,8 +499,12 @@ var _ = Describe("ChangeProcessor", func() {
465
499
{Namespace : "test" , Name : "hr-1" }: {
466
500
ObservedGeneration : hr1Updated .Generation ,
467
501
ParentStatuses : map [string ]state.ParentStatus {
468
- "listener-80-1" : {Attached : true },
469
- "listener-443-1" : {Attached : true },
502
+ "listener-80-1" : {
503
+ Conditions : conditions .NewDefaultRouteConditions (),
504
+ },
505
+ "listener-443-1" : {
506
+ Conditions : conditions .NewDefaultRouteConditions (),
507
+ },
470
508
},
471
509
},
472
510
},
@@ -475,7 +513,7 @@ var _ = Describe("ChangeProcessor", func() {
475
513
changed , conf , statuses := processor .Process (context .TODO ())
476
514
Expect (changed ).To (BeTrue ())
477
515
Expect (helpers .Diff (expectedConf , conf )).To (BeEmpty ())
478
- Expect ( helpers . Diff ( expectedStatuses , statuses )). To ( BeEmpty () )
516
+ assertStatuses ( expectedStatuses , statuses )
479
517
},
480
518
)
481
519
})
@@ -564,8 +602,12 @@ var _ = Describe("ChangeProcessor", func() {
564
602
{Namespace : "test" , Name : "hr-1" }: {
565
603
ObservedGeneration : hr1Updated .Generation ,
566
604
ParentStatuses : map [string ]state.ParentStatus {
567
- "listener-80-1" : {Attached : true },
568
- "listener-443-1" : {Attached : true },
605
+ "listener-80-1" : {
606
+ Conditions : conditions .NewDefaultRouteConditions (),
607
+ },
608
+ "listener-443-1" : {
609
+ Conditions : conditions .NewDefaultRouteConditions (),
610
+ },
569
611
},
570
612
},
571
613
},
@@ -574,7 +616,7 @@ var _ = Describe("ChangeProcessor", func() {
574
616
changed , conf , statuses := processor .Process (context .TODO ())
575
617
Expect (changed ).To (BeTrue ())
576
618
Expect (helpers .Diff (expectedConf , conf )).To (BeEmpty ())
577
- Expect ( helpers . Diff ( expectedStatuses , statuses )). To ( BeEmpty () )
619
+ assertStatuses ( expectedStatuses , statuses )
578
620
})
579
621
})
580
622
When ("the GatewayClass update without generation change is processed" , func () {
@@ -662,8 +704,12 @@ var _ = Describe("ChangeProcessor", func() {
662
704
{Namespace : "test" , Name : "hr-1" }: {
663
705
ObservedGeneration : hr1Updated .Generation ,
664
706
ParentStatuses : map [string ]state.ParentStatus {
665
- "listener-80-1" : {Attached : true },
666
- "listener-443-1" : {Attached : true },
707
+ "listener-80-1" : {
708
+ Conditions : conditions .NewDefaultRouteConditions (),
709
+ },
710
+ "listener-443-1" : {
711
+ Conditions : conditions .NewDefaultRouteConditions (),
712
+ },
667
713
},
668
714
},
669
715
},
@@ -672,7 +718,7 @@ var _ = Describe("ChangeProcessor", func() {
672
718
changed , conf , statuses := processor .Process (context .TODO ())
673
719
Expect (changed ).To (BeTrue ())
674
720
Expect (helpers .Diff (expectedConf , conf )).To (BeEmpty ())
675
- Expect ( helpers . Diff ( expectedStatuses , statuses )). To ( BeEmpty () )
721
+ assertStatuses ( expectedStatuses , statuses )
676
722
})
677
723
})
678
724
When ("no changes are captured" , func () {
@@ -763,8 +809,12 @@ var _ = Describe("ChangeProcessor", func() {
763
809
{Namespace : "test" , Name : "hr-1" }: {
764
810
ObservedGeneration : hr1Updated .Generation ,
765
811
ParentStatuses : map [string ]state.ParentStatus {
766
- "listener-80-1" : {Attached : true },
767
- "listener-443-1" : {Attached : true },
812
+ "listener-80-1" : {
813
+ Conditions : conditions .NewDefaultRouteConditions (),
814
+ },
815
+ "listener-443-1" : {
816
+ Conditions : conditions .NewDefaultRouteConditions (),
817
+ },
768
818
},
769
819
},
770
820
},
@@ -773,7 +823,7 @@ var _ = Describe("ChangeProcessor", func() {
773
823
changed , conf , statuses := processor .Process (context .TODO ())
774
824
Expect (changed ).To (BeTrue ())
775
825
Expect (helpers .Diff (expectedConf , conf )).To (BeEmpty ())
776
- Expect ( helpers . Diff ( expectedStatuses , statuses )). To ( BeEmpty () )
826
+ assertStatuses ( expectedStatuses , statuses )
777
827
})
778
828
})
779
829
When ("the second HTTPRoute is upserted" , func () {
@@ -853,15 +903,29 @@ var _ = Describe("ChangeProcessor", func() {
853
903
{Namespace : "test" , Name : "hr-1" }: {
854
904
ObservedGeneration : hr1Updated .Generation ,
855
905
ParentStatuses : map [string ]state.ParentStatus {
856
- "listener-80-1" : {Attached : true },
857
- "listener-443-1" : {Attached : true },
906
+ "listener-80-1" : {
907
+ Conditions : conditions .NewDefaultRouteConditions (),
908
+ },
909
+ "listener-443-1" : {
910
+ Conditions : conditions .NewDefaultRouteConditions (),
911
+ },
858
912
},
859
913
},
860
914
{Namespace : "test" , Name : "hr-2" }: {
861
915
ObservedGeneration : hr2 .Generation ,
862
916
ParentStatuses : map [string ]state.ParentStatus {
863
- "listener-80-1" : {Attached : false },
864
- "listener-443-1" : {Attached : false },
917
+ "listener-80-1" : {
918
+ Conditions : append (
919
+ conditions .NewDefaultRouteConditions (),
920
+ conditions .NewRouteTODO ("Gateway is ignored" ),
921
+ ),
922
+ },
923
+ "listener-443-1" : {
924
+ Conditions : append (
925
+ conditions .NewDefaultRouteConditions (),
926
+ conditions .NewRouteTODO ("Gateway is ignored" ),
927
+ ),
928
+ },
865
929
},
866
930
},
867
931
},
@@ -870,7 +934,7 @@ var _ = Describe("ChangeProcessor", func() {
870
934
changed , conf , statuses := processor .Process (context .TODO ())
871
935
Expect (changed ).To (BeTrue ())
872
936
Expect (helpers .Diff (expectedConf , conf )).To (BeEmpty ())
873
- Expect ( helpers . Diff ( expectedStatuses , statuses )). To ( BeEmpty () )
937
+ assertStatuses ( expectedStatuses , statuses )
874
938
})
875
939
})
876
940
When ("the first Gateway is deleted" , func () {
@@ -949,8 +1013,12 @@ var _ = Describe("ChangeProcessor", func() {
949
1013
{Namespace : "test" , Name : "hr-2" }: {
950
1014
ObservedGeneration : hr2 .Generation ,
951
1015
ParentStatuses : map [string ]state.ParentStatus {
952
- "listener-80-1" : {Attached : true },
953
- "listener-443-1" : {Attached : true },
1016
+ "listener-80-1" : {
1017
+ Conditions : conditions .NewDefaultRouteConditions (),
1018
+ },
1019
+ "listener-443-1" : {
1020
+ Conditions : conditions .NewDefaultRouteConditions (),
1021
+ },
954
1022
},
955
1023
},
956
1024
},
@@ -959,7 +1027,7 @@ var _ = Describe("ChangeProcessor", func() {
959
1027
changed , conf , statuses := processor .Process (context .TODO ())
960
1028
Expect (changed ).To (BeTrue ())
961
1029
Expect (helpers .Diff (expectedConf , conf )).To (BeEmpty ())
962
- Expect ( helpers . Diff ( expectedStatuses , statuses )). To ( BeEmpty () )
1030
+ assertStatuses ( expectedStatuses , statuses )
963
1031
})
964
1032
})
965
1033
When ("the second HTTPRoute is deleted" , func () {
@@ -1003,7 +1071,7 @@ var _ = Describe("ChangeProcessor", func() {
1003
1071
changed , conf , statuses := processor .Process (context .TODO ())
1004
1072
Expect (changed ).To (BeTrue ())
1005
1073
Expect (helpers .Diff (expectedConf , conf )).To (BeEmpty ())
1006
- Expect ( helpers . Diff ( expectedStatuses , statuses )). To ( BeEmpty () )
1074
+ assertStatuses ( expectedStatuses , statuses )
1007
1075
})
1008
1076
})
1009
1077
When ("the GatewayClass is deleted" , func () {
@@ -1035,7 +1103,7 @@ var _ = Describe("ChangeProcessor", func() {
1035
1103
changed , conf , statuses := processor .Process (context .TODO ())
1036
1104
Expect (changed ).To (BeTrue ())
1037
1105
Expect (helpers .Diff (expectedConf , conf )).To (BeEmpty ())
1038
- Expect ( helpers . Diff ( expectedStatuses , statuses )). To ( BeEmpty () )
1106
+ assertStatuses ( expectedStatuses , statuses )
1039
1107
})
1040
1108
})
1041
1109
When ("the second Gateway is deleted" , func () {
@@ -1054,7 +1122,7 @@ var _ = Describe("ChangeProcessor", func() {
1054
1122
changed , conf , statuses := processor .Process (context .TODO ())
1055
1123
Expect (changed ).To (BeTrue ())
1056
1124
Expect (helpers .Diff (expectedConf , conf )).To (BeEmpty ())
1057
- Expect ( helpers . Diff ( expectedStatuses , statuses )). To ( BeEmpty () )
1125
+ assertStatuses ( expectedStatuses , statuses )
1058
1126
})
1059
1127
})
1060
1128
When ("the first HTTPRoute is deleted" , func () {
@@ -1073,7 +1141,7 @@ var _ = Describe("ChangeProcessor", func() {
1073
1141
changed , conf , statuses := processor .Process (context .TODO ())
1074
1142
Expect (changed ).To (BeTrue ())
1075
1143
Expect (helpers .Diff (expectedConf , conf )).To (BeEmpty ())
1076
- Expect ( helpers . Diff ( expectedStatuses , statuses )). To ( BeEmpty () )
1144
+ assertStatuses ( expectedStatuses , statuses )
1077
1145
})
1078
1146
})
1079
1147
})
0 commit comments