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

Function TestDefaultContainer_DefinitionsOf

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

Source from the content-addressed store, hash-verified

460}
461
462func TestDefaultContainer_DefinitionsOf(t *testing.T) {
463 anyDefinition, _ := MakeDefinition(NewAnyComponent)
464 anotherDefinition, _ := MakeDefinition(NewAnotherComponent)
465
466 testCases := []struct {
467 name string
468 preCondition func(container Container)
469 typ reflect.Type
470
471 wantDefinitions []*Definition
472 }{
473 {
474 name: "no definition",
475 typ: reflect.TypeFor[*AnyComponent](),
476 wantDefinitions: []*Definition{},
477 },
478 {
479 name: "definitions by struct type",
480 preCondition: func(container Container) {
481 _ = container.RegisterDefinition(anyDefinition)
482
483 _ = container.RegisterDefinition(anotherDefinition)
484 },
485 typ: reflect.TypeFor[*AnyComponent](),
486 wantDefinitions: []*Definition{anyDefinition},
487 },
488 {
489 name: "definitions by interface type",
490 preCondition: func(container Container) {
491 _ = container.RegisterDefinition(anyDefinition)
492
493 _ = container.RegisterDefinition(anotherDefinition)
494 },
495 typ: reflect.TypeFor[AnyInterface](),
496 wantDefinitions: []*Definition{anyDefinition, anotherDefinition},
497 },
498 }
499
500 for _, tc := range testCases {
501 t.Run(tc.name, func(t *testing.T) {
502 // given
503 container := NewDefaultContainer()
504
505 if tc.preCondition != nil {
506 tc.preCondition(container)
507 }
508
509 // when
510 definitions := container.DefinitionsOf(tc.typ)
511
512 // then
513 assert.Len(t, definitions, len(tc.wantDefinitions))
514
515 for _, wantDefinition := range tc.wantDefinitions {
516 require.Contains(t, definitions, wantDefinition)
517 }
518 })
519 }

Callers

nothing calls this directly

Calls 6

RegisterDefinitionMethod · 0.95
DefinitionsOfMethod · 0.95
MakeDefinitionFunction · 0.85
NewDefaultContainerFunction · 0.85
LenMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected