@@ -14,9 +14,11 @@ import (
1414
1515var _ = Describe ("ChangeProcessor" , func () {
1616 Describe ("Normal cases of processing changes" , func () {
17- var hr1 , hr2 * v1alpha2.HTTPRoute
18- var gw * v1alpha2.Gateway
19- var processor newstate.ChangeProcessor
17+ var (
18+ hr1 , hr1Updated , hr2 * v1alpha2.HTTPRoute
19+ gw , gwUpdated * v1alpha2.Gateway
20+ processor newstate.ChangeProcessor
21+ )
2022
2123 BeforeEach (OncePerOrdered , func () {
2224 createRoute := func (name string , hostname string ) * v1alpha2.HTTPRoute {
@@ -54,6 +56,10 @@ var _ = Describe("ChangeProcessor", func() {
5456 }
5557
5658 hr1 = createRoute ("hr-1" , "foo.example.com" )
59+
60+ hr1Updated = hr1 .DeepCopy ()
61+ hr1Updated .Generation ++
62+
5763 hr2 = createRoute ("hr-2" , "bar.example.com" )
5864
5965 gw = & v1alpha2.Gateway {
@@ -73,6 +79,9 @@ var _ = Describe("ChangeProcessor", func() {
7379 },
7480 }
7581
82+ gwUpdated = gw .DeepCopy ()
83+ gwUpdated .Generation ++
84+
7685 processor = newstate .NewChangeProcessorImpl (types.NamespacedName {Namespace : "test" , Name : "gateway" })
7786 })
7887
@@ -149,6 +158,116 @@ var _ = Describe("ChangeProcessor", func() {
149158 Expect (helpers .Diff (expectedStatuses , statuses )).To (BeEmpty ())
150159 })
151160
161+ It ("should return empty configuration and statuses after processing upserting the HTTPRoute without generation change" , func () {
162+ hr1UpdatedSameGen := hr1 .DeepCopy ()
163+ // hr1UpdatedSameGen.Generation has not been changed
164+ processor .CaptureUpsertChange (hr1UpdatedSameGen )
165+
166+ changed , conf , statuses := processor .Process ()
167+ Expect (changed ).To (BeFalse ())
168+ Expect (conf ).To (BeZero ())
169+ Expect (statuses ).To (BeZero ())
170+ })
171+
172+ It ("should return updated configuration and statuses after upserting the HTTPRoute with generation change" , func () {
173+ processor .CaptureUpsertChange (hr1Updated )
174+
175+ expectedConf := newstate.Configuration {
176+ HTTPServers : []newstate.HTTPServer {
177+ {
178+ Hostname : "foo.example.com" ,
179+ PathRules : []newstate.PathRule {
180+ {
181+ Path : "/" ,
182+ MatchRules : []newstate.MatchRule {
183+ {
184+ MatchIdx : 0 ,
185+ RuleIdx : 0 ,
186+ Source : hr1Updated ,
187+ },
188+ },
189+ },
190+ },
191+ },
192+ },
193+ }
194+ expectedStatuses := newstate.Statuses {
195+ ListenerStatuses : map [string ]newstate.ListenerStatus {
196+ "listener-80-1" : {
197+ Valid : true ,
198+ AttachedRoutes : 1 ,
199+ },
200+ },
201+ HTTPRouteStatuses : map [types.NamespacedName ]newstate.HTTPRouteStatus {
202+ {Namespace : "test" , Name : "hr-1" }: {
203+ ParentStatuses : map [string ]newstate.ParentStatus {
204+ "listener-80-1" : {Attached : true },
205+ },
206+ },
207+ },
208+ }
209+
210+ changed , conf , statuses := processor .Process ()
211+ Expect (changed ).To (BeTrue ())
212+ Expect (helpers .Diff (expectedConf , conf )).To (BeEmpty ())
213+ Expect (helpers .Diff (expectedStatuses , statuses )).To (BeEmpty ())
214+ })
215+
216+ It ("should return empty configuration and statuses after processing upserting the Gateway without generation change" , func () {
217+ gwUpdatedSameGen := gw .DeepCopy ()
218+ // gwUpdatedSameGen.Generation has not been changed
219+ processor .CaptureUpsertChange (gwUpdatedSameGen )
220+
221+ changed , conf , statuses := processor .Process ()
222+ Expect (changed ).To (BeFalse ())
223+ Expect (conf ).To (BeZero ())
224+ Expect (statuses ).To (BeZero ())
225+ })
226+
227+ It ("should return updated configuration and statuses after upserting the Gateway with generation change" , func () {
228+ processor .CaptureUpsertChange (gwUpdated )
229+
230+ expectedConf := newstate.Configuration {
231+ HTTPServers : []newstate.HTTPServer {
232+ {
233+ Hostname : "foo.example.com" ,
234+ PathRules : []newstate.PathRule {
235+ {
236+ Path : "/" ,
237+ MatchRules : []newstate.MatchRule {
238+ {
239+ MatchIdx : 0 ,
240+ RuleIdx : 0 ,
241+ Source : hr1Updated ,
242+ },
243+ },
244+ },
245+ },
246+ },
247+ },
248+ }
249+ expectedStatuses := newstate.Statuses {
250+ ListenerStatuses : map [string ]newstate.ListenerStatus {
251+ "listener-80-1" : {
252+ Valid : true ,
253+ AttachedRoutes : 1 ,
254+ },
255+ },
256+ HTTPRouteStatuses : map [types.NamespacedName ]newstate.HTTPRouteStatus {
257+ {Namespace : "test" , Name : "hr-1" }: {
258+ ParentStatuses : map [string ]newstate.ParentStatus {
259+ "listener-80-1" : {Attached : true },
260+ },
261+ },
262+ },
263+ }
264+
265+ changed , conf , statuses := processor .Process ()
266+ Expect (changed ).To (BeTrue ())
267+ Expect (helpers .Diff (expectedConf , conf )).To (BeEmpty ())
268+ Expect (helpers .Diff (expectedStatuses , statuses )).To (BeEmpty ())
269+ })
270+
152271 It ("should return empty configuration and statuses after processing without capturing any changes" , func () {
153272 changed , conf , statuses := processor .Process ()
154273
@@ -186,7 +305,7 @@ var _ = Describe("ChangeProcessor", func() {
186305 {
187306 MatchIdx : 0 ,
188307 RuleIdx : 0 ,
189- Source : hr1 ,
308+ Source : hr1Updated ,
190309 },
191310 },
192311 },
@@ -235,7 +354,7 @@ var _ = Describe("ChangeProcessor", func() {
235354 {
236355 MatchIdx : 0 ,
237356 RuleIdx : 0 ,
238- Source : hr1 ,
357+ Source : hr1Updated ,
239358 },
240359 },
241360 },
0 commit comments