(t *testing.T)
| 669 | } |
| 670 | |
| 671 | func TestDefaultContainer_RemoveSingleton(t *testing.T) { |
| 672 | testCases := []struct { |
| 673 | name string |
| 674 | preCondition func(container Container) |
| 675 | singletonName string |
| 676 | |
| 677 | wantErr error |
| 678 | }{ |
| 679 | { |
| 680 | name: "no singleton", |
| 681 | singletonName: "anySingletonName", |
| 682 | wantErr: ErrInstanceNotFound, |
| 683 | }, |
| 684 | { |
| 685 | name: "valid singleton", |
| 686 | preCondition: func(container Container) { |
| 687 | _ = container.RegisterSingleton("anySingletonName", AnyComponent{}) |
| 688 | }, |
| 689 | singletonName: "anySingletonName", |
| 690 | wantErr: nil, |
| 691 | }, |
| 692 | } |
| 693 | |
| 694 | for _, tc := range testCases { |
| 695 | t.Run(tc.name, func(t *testing.T) { |
| 696 | // given |
| 697 | container := NewDefaultContainer() |
| 698 | |
| 699 | if tc.preCondition != nil { |
| 700 | tc.preCondition(container) |
| 701 | } |
| 702 | |
| 703 | // when |
| 704 | err := container.RemoveSingleton(tc.singletonName) |
| 705 | |
| 706 | // then |
| 707 | if tc.wantErr != nil { |
| 708 | require.Error(t, err) |
| 709 | require.EqualError(t, err, tc.wantErr.Error()) |
| 710 | return |
| 711 | } |
| 712 | |
| 713 | assert.NoError(t, err) |
| 714 | }) |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | func TestDefaultContainer_CanResolve(t *testing.T) { |
| 719 | var testCases = []struct { |
nothing calls this directly
no test coverage detected