@@ -287,6 +287,74 @@ func TestChecksController_Reconcile(t *testing.T) {
287
287
}
288
288
}
289
289
290
+ // TestChecksController_Reconcile_Update tests the update of the checks
291
+ // when the runtime configuration changes.
292
+ func TestChecksController_Reconcile_Update (t * testing.T ) {
293
+ ctx , cancel := logger .NewContextWithLogger (context .Background ())
294
+ defer cancel ()
295
+
296
+ tests := []struct {
297
+ name string
298
+ checks []checks.Check
299
+ newRuntimeConfig runtime.Config
300
+ }{
301
+ {
302
+ name : "update health check" ,
303
+ checks : []checks.Check {
304
+ health .NewCheck (),
305
+ },
306
+ newRuntimeConfig : runtime.Config {
307
+ Health : & health.Config {
308
+ Targets : []string {"https://new.com" },
309
+ Interval : 200 * time .Millisecond ,
310
+ Timeout : 1000 * time .Millisecond ,
311
+ },
312
+ },
313
+ },
314
+ {
315
+ name : "update health & latency check" ,
316
+ checks : []checks.Check {
317
+ health .NewCheck (),
318
+ latency .NewCheck (),
319
+ },
320
+ newRuntimeConfig : runtime.Config {
321
+ Health : & health.Config {
322
+ Targets : []string {"https://new.com" },
323
+ Interval : 200 * time .Millisecond ,
324
+ Timeout : 1000 * time .Millisecond ,
325
+ },
326
+ Latency : & latency.Config {
327
+ Targets : []string {"https://new.com" },
328
+ Interval : 200 * time .Millisecond ,
329
+ Timeout : 1000 * time .Millisecond ,
330
+ },
331
+ },
332
+ },
333
+ }
334
+
335
+ for _ , tt := range tests {
336
+ t .Run (tt .name , func (t * testing.T ) {
337
+ cc := NewChecksController (db .NewInMemory (), metrics .New (metrics.Config {}))
338
+ for _ , c := range tt .checks {
339
+ cc .checks .Add (c )
340
+ }
341
+
342
+ cc .Reconcile (ctx , tt .newRuntimeConfig )
343
+
344
+ for _ , c := range cc .checks .Iter () {
345
+ switch c .GetConfig ().For () {
346
+ case health .CheckName :
347
+ hc := c .(* health.Health )
348
+ assert .Equal (t , tt .newRuntimeConfig .Health .Targets , hc .GetConfig ().(* health.Config ).Targets )
349
+ case latency .CheckName :
350
+ lc := c .(* latency.Latency )
351
+ assert .Equal (t , tt .newRuntimeConfig .Latency .Targets , lc .GetConfig ().(* latency.Config ).Targets )
352
+ }
353
+ }
354
+ })
355
+ }
356
+ }
357
+
290
358
func TestChecksController_RegisterCheck (t * testing.T ) {
291
359
tests := []struct {
292
360
name string
0 commit comments