@@ -411,7 +411,16 @@ func TestScope_HealthCheckWithContext(t *testing.T) {
411
411
}
412
412
413
413
func TestScope_Shutdown (t * testing.T ) {
414
- // @TODO
414
+ is := assert .New (t )
415
+
416
+ i := New ()
417
+
418
+ ProvideNamedValue (i , "lazy-ok" , & lazyTestShutdownerOK {})
419
+ ProvideNamedValue (i , "lazy-ko" , & lazyTestShutdownerKO {})
420
+ _ , _ = InvokeNamed [* lazyTestShutdownerOK ](i , "lazy-ok" )
421
+ _ , _ = InvokeNamed [* lazyTestShutdownerKO ](i , "lazy-ko" )
422
+
423
+ is .EqualValues (map [string ]error {"lazy-ok" : nil , "lazy-ko" : assert .AnError }, i .Shutdown ())
415
424
}
416
425
417
426
// @TODO: missing tests for context
@@ -426,11 +435,11 @@ func TestScope_ShutdownWithContext(t *testing.T) {
426
435
child2a := child1 .Scope ("child2a" )
427
436
child2b := child1 .Scope ("child2b" )
428
437
429
- provider1 := func (i Injector ) (* lazyTestHeathcheckerOK , error ) {
430
- return & lazyTestHeathcheckerOK {foobar : "foobar" }, nil
438
+ provider1 := func (i Injector ) (* lazyTestShutdownerOK , error ) {
439
+ return & lazyTestShutdownerOK {foobar : "foobar" }, nil
431
440
}
432
- provider2 := func (i Injector ) (* lazyTestHeathcheckerKO , error ) {
433
- return & lazyTestHeathcheckerKO {foobar : "foobar" }, nil
441
+ provider2 := func (i Injector ) (* lazyTestShutdownerKO , error ) {
442
+ return & lazyTestShutdownerKO {foobar : "foobar" }, nil
434
443
}
435
444
436
445
rootScope .serviceSet ("root-a" , newServiceLazy ("root-a" , provider2 ))
@@ -439,39 +448,39 @@ func TestScope_ShutdownWithContext(t *testing.T) {
439
448
child2a .serviceSet ("child2a-b" , newServiceLazy ("child2a-b" , provider2 ))
440
449
child2b .serviceSet ("child2b-a" , newServiceLazy ("child2b-a" , provider2 ))
441
450
442
- _ , _ = invokeByName [* lazyTestHeathcheckerKO ](rootScope , "root-a" )
443
- _ , _ = invokeByName [* lazyTestHeathcheckerOK ](child1 , "child1-a" )
444
- _ , _ = invokeByName [* lazyTestHeathcheckerOK ](child2a , "child2a-a" )
445
- _ , _ = invokeByName [* lazyTestHeathcheckerKO ](child2a , "child2a-b" )
446
- _ , _ = invokeByName [* lazyTestHeathcheckerKO ](child2b , "child2b-a" )
451
+ _ , _ = invokeByName [* lazyTestShutdownerKO ](rootScope , "root-a" )
452
+ _ , _ = invokeByName [* lazyTestShutdownerOK ](child1 , "child1-a" )
453
+ _ , _ = invokeByName [* lazyTestShutdownerOK ](child2a , "child2a-a" )
454
+ _ , _ = invokeByName [* lazyTestShutdownerKO ](child2a , "child2a-b" )
455
+ _ , _ = invokeByName [* lazyTestShutdownerKO ](child2b , "child2b-a" )
447
456
448
457
// from rootScope POV
449
- is .Equal (assert .AnError , rootScope .serviceHealthCheck (ctx , "root-a" ))
450
- is .ErrorContains (rootScope .serviceHealthCheck (ctx , "child1-a" ), "could not find service" )
451
- is .ErrorContains (rootScope .serviceHealthCheck (ctx , "child2a-a" ), "could not find service" )
452
- is .ErrorContains (rootScope .serviceHealthCheck (ctx , "child2a-b" ), "could not find service" )
453
- is .ErrorContains (rootScope .serviceHealthCheck (ctx , "child2b-a" ), "could not find service" )
458
+ is .Equal (assert .AnError , rootScope .serviceShutdown (ctx , "root-a" ))
459
+ is .ErrorContains (rootScope .serviceShutdown (ctx , "child1-a" ), "could not find service" )
460
+ is .ErrorContains (rootScope .serviceShutdown (ctx , "child2a-a" ), "could not find service" )
461
+ is .ErrorContains (rootScope .serviceShutdown (ctx , "child2a-b" ), "could not find service" )
462
+ is .ErrorContains (rootScope .serviceShutdown (ctx , "child2b-a" ), "could not find service" )
454
463
455
464
// from child1 POV
456
- is .ErrorContains (child1 .serviceHealthCheck (ctx , "root-a" ), "could not find service" )
457
- is .Equal (nil , child1 .serviceHealthCheck (ctx , "child1-a" ))
458
- is .ErrorContains (child1 .serviceHealthCheck (ctx , "child2a-a" ), "could not find service" )
459
- is .ErrorContains (child1 .serviceHealthCheck (ctx , "child2a-b" ), "could not find service" )
460
- is .ErrorContains (child1 .serviceHealthCheck (ctx , "child2b-a" ), "could not find service" )
465
+ is .ErrorContains (child1 .serviceShutdown (ctx , "root-a" ), "could not find service" )
466
+ is .Equal (nil , child1 .serviceShutdown (ctx , "child1-a" ))
467
+ is .ErrorContains (child1 .serviceShutdown (ctx , "child2a-a" ), "could not find service" )
468
+ is .ErrorContains (child1 .serviceShutdown (ctx , "child2a-b" ), "could not find service" )
469
+ is .ErrorContains (child1 .serviceShutdown (ctx , "child2b-a" ), "could not find service" )
461
470
462
471
// from child2a POV
463
- is .ErrorContains (child2a .serviceHealthCheck (ctx , "root-a" ), "could not find service" )
464
- is .ErrorContains (child2a .serviceHealthCheck (ctx , "child1-a" ), "could not find service" )
465
- is .Equal (nil , child2a .serviceHealthCheck (ctx , "child2a-a" ))
466
- is .Equal (assert .AnError , child2a .serviceHealthCheck (ctx , "child2a-b" ))
467
- is .ErrorContains (child2a .serviceHealthCheck (ctx , "child2b-a" ), "could not find service" )
472
+ is .ErrorContains (child2a .serviceShutdown (ctx , "root-a" ), "could not find service" )
473
+ is .ErrorContains (child2a .serviceShutdown (ctx , "child1-a" ), "could not find service" )
474
+ is .Equal (nil , child2a .serviceShutdown (ctx , "child2a-a" ))
475
+ is .Equal (assert .AnError , child2a .serviceShutdown (ctx , "child2a-b" ))
476
+ is .ErrorContains (child2a .serviceShutdown (ctx , "child2b-a" ), "could not find service" )
468
477
469
478
// from child2b POV
470
- is .ErrorContains (child2b .serviceHealthCheck (ctx , "root-a" ), "could not find service" )
471
- is .ErrorContains (child2b .serviceHealthCheck (ctx , "child1-a" ), "could not find service" )
472
- is .ErrorContains (child2b .serviceHealthCheck (ctx , "child2a-a" ), "could not find service" )
473
- is .ErrorContains (child2b .serviceHealthCheck (ctx , "child2a-b" ), "could not find service" )
474
- is .Equal (assert .AnError , child2b .serviceHealthCheck (ctx , "child2b-a" ))
479
+ is .ErrorContains (child2b .serviceShutdown (ctx , "root-a" ), "could not find service" )
480
+ is .ErrorContains (child2b .serviceShutdown (ctx , "child1-a" ), "could not find service" )
481
+ is .ErrorContains (child2b .serviceShutdown (ctx , "child2a-a" ), "could not find service" )
482
+ is .ErrorContains (child2b .serviceShutdown (ctx , "child2a-b" ), "could not find service" )
483
+ is .Equal (assert .AnError , child2b .serviceShutdown (ctx , "child2b-a" ))
475
484
}
476
485
477
486
func TestScope_clone (t * testing.T ) {
@@ -531,7 +540,7 @@ func TestScope_serviceHealthCheck(t *testing.T) {
531
540
_ , _ = invokeByName [int ](child3 , "child3-a" )
532
541
533
542
is .ElementsMatch ([]EdgeService {newEdgeService (child3 .id , child3 .name , "child3-a" ), newEdgeService (child2a .id , child2a .name , "child2a-a" ), newEdgeService (child2a .id , child2a .name , "child2a-b" ), newEdgeService (child1 .id , child1 .name , "child1-a" )}, child3 .ListInvokedServices ())
534
- is .Nil ( child1 .Shutdown ())
543
+ is .EqualValues ( map [ string ] error { "child1-a" : nil , "child2a-a" : nil , "child2a-b" : nil , "child2b-a" : nil , "child3-a" : nil }, child1 .Shutdown ())
535
544
is .ElementsMatch ([]EdgeService {}, child3 .ListInvokedServices ())
536
545
}
537
546
0 commit comments