(t *testing.T)
| 460 | } |
| 461 | |
| 462 | func 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 | } |
nothing calls this directly
no test coverage detected