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

Function TestCreateConstructor

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

Source from the content-addressed store, hash-verified

24)
25
26func TestCreateConstructor(t *testing.T) {
27 testCases := []struct {
28 name string
29 constructorFn ConstructorFunc
30
31 wantOutType reflect.Type
32 wantArgs []Arg
33 wantErr error
34 }{
35 {
36 name: "nil constructor function",
37 constructorFn: nil,
38 wantErr: errors.New("nil constructor"),
39 },
40 {
41 name: "invalid constructor function",
42 constructorFn: "string value",
43 wantErr: errors.New("constructor must be a function"),
44 },
45 {
46 name: "multi result constructor function",
47 constructorFn: func() (string, int, error) {
48 return "", -1, nil
49 },
50 wantErr: errors.New("constructor must only return one result"),
51 },
52 {
53 name: "valid constructor function",
54 constructorFn: NewAnotherComponent,
55 wantOutType: reflect.TypeFor[*AnotherComponent](),
56 wantArgs: []Arg{
57 {
58 0,
59 "",
60 reflect.TypeFor[DependentComponent](),
61 },
62 },
63 },
64 }
65
66 for _, tc := range testCases {
67 t.Run(tc.name, func(t *testing.T) {
68 // given
69
70 // when
71 constructor, err := createConstructor(tc.constructorFn)
72
73 // then
74 if tc.wantErr != nil {
75 require.Equal(t, Constructor{}, constructor)
76
77 require.Error(t, err)
78 require.EqualError(t, err, tc.wantErr.Error())
79 return
80 }
81
82 assert.NoError(t, err)
83 assert.Equal(t, tc.wantOutType, constructor.OutType())

Callers

nothing calls this directly

Calls 8

createConstructorFunction · 0.85
OutTypeMethod · 0.80
LenMethod · 0.80
ArgsMethod · 0.80
IndexMethod · 0.80
RunMethod · 0.65
NameMethod · 0.65
TypeMethod · 0.45

Tested by

no test coverage detected