(t *testing.T)
| 97 | } |
| 98 | |
| 99 | func TestConstructor_Invoke(t *testing.T) { |
| 100 | testCases := []struct { |
| 101 | name string |
| 102 | constructorFn ConstructorFunc |
| 103 | inputs []any |
| 104 | |
| 105 | wantOutType reflect.Type |
| 106 | wantErr error |
| 107 | }{ |
| 108 | { |
| 109 | name: "invalid parameter count", |
| 110 | constructorFn: NewAnotherComponent, |
| 111 | wantErr: errors.New("invalid parameter count, expected 1 but got 0"), |
| 112 | }, |
| 113 | { |
| 114 | name: "invalid parameter", |
| 115 | constructorFn: NewAnotherComponent, |
| 116 | inputs: []any{ |
| 117 | "invalid parameter", |
| 118 | }, |
| 119 | wantErr: errors.New("expected DependentComponent but got string at index 0"), |
| 120 | }, |
| 121 | { |
| 122 | name: "nil parameter", |
| 123 | constructorFn: NewAnotherComponent, |
| 124 | inputs: []any{ |
| 125 | nil, |
| 126 | }, |
| 127 | wantOutType: reflect.TypeFor[*AnotherComponent](), |
| 128 | }, |
| 129 | { |
| 130 | name: "valid constructor", |
| 131 | constructorFn: NewAnotherComponent, |
| 132 | inputs: []any{ |
| 133 | DependentComponent{}, |
| 134 | }, |
| 135 | wantOutType: reflect.TypeFor[*AnotherComponent](), |
| 136 | }, |
| 137 | { |
| 138 | name: "invalid variadic parameter", |
| 139 | constructorFn: func(dependents ...DependentComponent) *AnotherComponent { |
| 140 | return &AnotherComponent{} |
| 141 | }, |
| 142 | inputs: []any{ |
| 143 | "invalid parameter", |
| 144 | }, |
| 145 | wantErr: errors.New("expected DependentComponent but got string at index 0"), |
| 146 | }, |
| 147 | { |
| 148 | name: "nil variadic parameter", |
| 149 | constructorFn: func(dependents ...DependentComponent) *AnotherComponent { |
| 150 | return &AnotherComponent{} |
| 151 | }, |
| 152 | inputs: []any{ |
| 153 | nil, |
| 154 | }, |
| 155 | wantOutType: reflect.TypeFor[*AnotherComponent](), |
| 156 | }, |
nothing calls this directly
no test coverage detected