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

Function TestDefaultContainer_Resolve

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

Source from the content-addressed store, hash-verified

820}
821
822func TestDefaultContainer_Resolve(t *testing.T) {
823 var testCases = []struct {
824 name string
825 ctx context.Context
826 preCondition func(container Container)
827 instanceName string
828
829 wantErr error
830 wantTyp reflect.Type
831 }{
832 {
833 name: "empty name",
834 instanceName: "",
835 wantErr: errors.New("empty name"),
836 },
837 {
838 name: "resolve singleton already in container",
839 preCondition: func(container Container) {
840 _ = container.RegisterSingleton("anyInstanceName", AnyComponent{})
841 },
842 instanceName: "anyInstanceName",
843 wantTyp: reflect.TypeFor[AnyComponent](),
844 },
845 {
846 name: "resolve from singleton definition",
847 preCondition: func(container Container) {
848 def, _ := MakeDefinition(NewAnyComponent, WithName("anyInstanceName"))
849 _ = container.RegisterDefinition(def)
850 },
851 instanceName: "anyInstanceName",
852 wantTyp: reflect.TypeFor[*AnyComponent](),
853 },
854 {
855 name: "no singleton/definition",
856 instanceName: "anyInstanceName",
857 wantTyp: reflect.TypeFor[*AnyComponent](),
858 wantErr: ErrDefinitionNotFound,
859 },
860 {
861 name: "resolve from prototype definition",
862 preCondition: func(container Container) {
863 def, _ := MakeDefinition(NewAnyComponent, WithName("anyInstanceName"), WithScope(PrototypeScope))
864 _ = container.RegisterDefinition(def)
865 },
866 instanceName: "anyInstanceName",
867 wantTyp: reflect.TypeFor[*AnyComponent](),
868 },
869 {
870 name: "no scope",
871 preCondition: func(container Container) {
872 def, _ := MakeDefinition(NewAnyComponent, WithName("anyInstanceName"), WithScope("anyScope"))
873 _ = container.RegisterDefinition(def)
874 },
875 instanceName: "anyInstanceName",
876 wantErr: ErrScopeNotFound,
877 },
878 {
879 name: "resolve from custom scope",

Callers

nothing calls this directly

Calls 9

RegisterSingletonMethod · 0.95
RegisterDefinitionMethod · 0.95
RegisterScopeMethod · 0.95
ResolveMethod · 0.95
MakeDefinitionFunction · 0.85
WithNameFunction · 0.85
WithScopeFunction · 0.85
NewDefaultContainerFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected