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

Function TestDefaultContainer_RegisterScope

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

Source from the content-addressed store, hash-verified

1190}
1191
1192func TestDefaultContainer_RegisterScope(t *testing.T) {
1193 testCases := []struct {
1194 name string
1195 scopeName string
1196 scope Scope
1197
1198 wantErr error
1199 }{
1200 {
1201 name: "invalid scope name",
1202 wantErr: ErrInvalidScopeName,
1203 },
1204 {
1205 name: "nil scope",
1206 scopeName: "anyScopeName",
1207 scope: nil,
1208 wantErr: errors.New("nil scope"),
1209 },
1210 {
1211 name: "singleton scope replacement not allowed",
1212 scopeName: SingletonScope,
1213 scope: &AnyScope{},
1214 wantErr: ErrScopeReplacementNotAllowed,
1215 },
1216 {
1217 name: "prototype scope replacement not allowed",
1218 scopeName: PrototypeScope,
1219 scope: &AnyScope{},
1220 wantErr: ErrScopeReplacementNotAllowed,
1221 },
1222 {
1223 name: "valid scope",
1224 scopeName: "anyScopeName",
1225 scope: &AnyScope{},
1226 wantErr: nil,
1227 },
1228 }
1229
1230 for _, tc := range testCases {
1231 t.Run(tc.name, func(t *testing.T) {
1232 // given
1233 container := NewDefaultContainer()
1234
1235 // when
1236 err := container.RegisterScope(tc.scopeName, tc.scope)
1237
1238 // then
1239 if tc.wantErr != nil {
1240 require.Error(t, err)
1241 require.EqualError(t, err, tc.wantErr.Error())
1242 return
1243 }
1244
1245 assert.NoError(t, err)
1246 })
1247 }
1248}
1249

Callers

nothing calls this directly

Calls 3

RegisterScopeMethod · 0.95
NewDefaultContainerFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected