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

Function TestConstructor_Invoke

component/constructor_test.go:99–191  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

97}
98
99func 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 },

Callers

nothing calls this directly

Calls 3

createConstructorFunction · 0.85
RunMethod · 0.65
InvokeMethod · 0.65

Tested by

no test coverage detected