(t *testing.T)
| 820 | } |
| 821 | |
| 822 | func 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", |
nothing calls this directly
no test coverage detected