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

Function TestDefaultContainer_Initialize

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

Source from the content-addressed store, hash-verified

1380}
1381
1382func TestDefaultContainer_Initialize(t *testing.T) {
1383
1384 testCases := []struct {
1385 name string
1386 ctx context.Context
1387 preCondition func(container Container)
1388 instanceName string
1389
1390 wantErr error
1391 wantTyp reflect.Type
1392 }{
1393 {
1394 name: "initialize error",
1395 preCondition: func(container Container) {
1396 def, _ := MakeDefinition(NewAnyComponentWithInitializer, WithName("anyInstanceName"))
1397 _ = container.RegisterDefinition(def)
1398
1399 mockObj := &mock.Mock{}
1400 _ = container.RegisterSingleton("anyMockName", mockObj)
1401 mockObj.On("Init", mock.AnythingOfType("*context.valueCtx")).Return(errors.New("init error"))
1402 },
1403 instanceName: "anyInstanceName",
1404 wantErr: errors.New("init error"),
1405 },
1406 {
1407 name: "no initialize error",
1408 preCondition: func(container Container) {
1409 def, _ := MakeDefinition(NewAnyComponentWithInitializer, WithName("anyInstanceName"))
1410 _ = container.RegisterDefinition(def)
1411
1412 mockObj := &mock.Mock{}
1413 _ = container.RegisterSingleton("anyMockName", mockObj)
1414 mockObj.On("Init", mock.AnythingOfType("*context.valueCtx")).Return(nil)
1415 },
1416 instanceName: "anyInstanceName",
1417 wantTyp: reflect.TypeFor[*AnyComponentWithInitializer](),
1418 },
1419 {
1420 name: "pre processor error",
1421 preCondition: func(container Container) {
1422 def, _ := MakeDefinition(NewAnyComponent, WithName("anyInstanceName"))
1423 _ = container.RegisterDefinition(def)
1424
1425 anyPreprocessor := &AnyPreProcessor{}
1426 _ = container.UsePreProcessor(anyPreprocessor)
1427 anyPreprocessor.On("ProcessBeforeInit", mock.Anything, mock.Anything).
1428 Return(nil, errors.New("pre processor error"))
1429 },
1430 instanceName: "anyInstanceName",
1431 wantErr: errors.New("pre processor error"),
1432 },
1433 {
1434 name: "apply pre processor",
1435 preCondition: func(container Container) {
1436 def, _ := MakeDefinition(NewAnyComponent, WithName("anyInstanceName"))
1437 _ = container.RegisterDefinition(def)
1438
1439 anyPreprocessor := &AnyPreProcessor{}

Callers

nothing calls this directly

Calls 9

RegisterDefinitionMethod · 0.95
RegisterSingletonMethod · 0.95
UsePreProcessorMethod · 0.95
UsePostProcessorMethod · 0.95
ResolveMethod · 0.95
MakeDefinitionFunction · 0.85
WithNameFunction · 0.85
NewDefaultContainerFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected