MCPcopy Create free account
hub / github.com/codnect/procyon / TestDefaultContainer_Singleton

Function TestDefaultContainer_Singleton

component/container_test.go:624–669  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

622}
623
624func TestDefaultContainer_Singleton(t *testing.T) {
625 anySingleton := &AnyComponent{}
626
627 testCases := []struct {
628 name string
629 preCondition func(container Container)
630 singletonName string
631
632 wantResult bool
633 wantSingleton any
634 }{
635 {
636 name: "no singleton",
637 singletonName: "anySingletonName",
638 wantResult: false,
639 },
640 {
641 name: "valid singleton",
642 preCondition: func(container Container) {
643 _ = container.RegisterSingleton("anySingletonName", anySingleton)
644 },
645 singletonName: "anySingletonName",
646 wantResult: true,
647 wantSingleton: anySingleton,
648 },
649 }
650
651 for _, tc := range testCases {
652 t.Run(tc.name, func(t *testing.T) {
653 // given
654 container := NewDefaultContainer()
655
656 if tc.preCondition != nil {
657 tc.preCondition(container)
658 }
659
660 // when
661 singleton, exists := container.Singleton(tc.singletonName)
662
663 // then
664 require.Equal(t, tc.wantResult, exists)
665 require.Equal(t, tc.wantSingleton, singleton)
666 })
667 }
668
669}
670
671func TestDefaultContainer_RemoveSingleton(t *testing.T) {
672 testCases := []struct {

Callers

nothing calls this directly

Calls 4

RegisterSingletonMethod · 0.95
SingletonMethod · 0.95
NewDefaultContainerFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected