(t *testing.T)
| 86 | } |
| 87 | |
| 88 | func TestRegister(t *testing.T) { |
| 89 | testCases := []struct { |
| 90 | name string |
| 91 | preCondition func() |
| 92 | constructorFn ConstructorFunc |
| 93 | opts []DefinitionOption |
| 94 | conditions []Condition |
| 95 | wantName string |
| 96 | wantScope string |
| 97 | wantType reflect.Type |
| 98 | wantConditions []Condition |
| 99 | wantPanic error |
| 100 | }{ |
| 101 | { |
| 102 | name: "nil constructor", |
| 103 | constructorFn: nil, |
| 104 | wantPanic: errors.New("nil constructor"), |
| 105 | }, |
| 106 | { |
| 107 | name: "already exists", |
| 108 | preCondition: func() { |
| 109 | components["anyComponent"] = &Component{} |
| 110 | }, |
| 111 | constructorFn: NewAnyComponent, |
| 112 | wantPanic: errors.New("component with name 'anyComponent' already exists"), |
| 113 | }, |
| 114 | { |
| 115 | name: "without options", |
| 116 | constructorFn: NewAnyComponent, |
| 117 | wantName: "anyComponent", |
| 118 | wantScope: SingletonScope, |
| 119 | wantType: reflect.TypeFor[*AnyComponent](), |
| 120 | }, |
| 121 | { |
| 122 | name: "with custom name", |
| 123 | constructorFn: NewAnyComponent, |
| 124 | opts: []DefinitionOption{ |
| 125 | WithName("customName"), |
| 126 | }, |
| 127 | wantName: "customName", |
| 128 | wantScope: SingletonScope, |
| 129 | wantType: reflect.TypeFor[*AnyComponent](), |
| 130 | }, |
| 131 | { |
| 132 | name: "with prototype scope", |
| 133 | constructorFn: NewAnyComponent, |
| 134 | opts: []DefinitionOption{ |
| 135 | WithScope(PrototypeScope), |
| 136 | }, |
| 137 | wantName: "anyComponent", |
| 138 | wantScope: PrototypeScope, |
| 139 | wantType: reflect.TypeFor[*AnyComponent](), |
| 140 | }, |
| 141 | { |
| 142 | name: "with custom scope", |
| 143 | constructorFn: NewAnyComponent, |
| 144 | opts: []DefinitionOption{ |
| 145 | WithScope("anyScope"), |
nothing calls this directly
no test coverage detected