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

Function TestRegister

component/component_test.go:88–208  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

86}
87
88func TestRegister(t *testing.T) {
89 testCases := []struct {
90 name string
91 preCondition func()
92 constructorFn ConstructorFunc
93 opts []DefinitionOption
94 conditions []Condition
95 wantName string
96 wantScope string
97 wantType reflect.Type
98 wantConditions []Condition
99 wantPanic error
100 }{
101 {
102 name: "nil constructor",
103 constructorFn: nil,
104 wantPanic: errors.New("nil constructor"),
105 },
106 {
107 name: "already exists",
108 preCondition: func() {
109 components["anyComponent"] = &Component{}
110 },
111 constructorFn: NewAnyComponent,
112 wantPanic: errors.New("component with name 'anyComponent' already exists"),
113 },
114 {
115 name: "without options",
116 constructorFn: NewAnyComponent,
117 wantName: "anyComponent",
118 wantScope: SingletonScope,
119 wantType: reflect.TypeFor[*AnyComponent](),
120 },
121 {
122 name: "with custom name",
123 constructorFn: NewAnyComponent,
124 opts: []DefinitionOption{
125 WithName("customName"),
126 },
127 wantName: "customName",
128 wantScope: SingletonScope,
129 wantType: reflect.TypeFor[*AnyComponent](),
130 },
131 {
132 name: "with prototype scope",
133 constructorFn: NewAnyComponent,
134 opts: []DefinitionOption{
135 WithScope(PrototypeScope),
136 },
137 wantName: "anyComponent",
138 wantScope: PrototypeScope,
139 wantType: reflect.TypeFor[*AnyComponent](),
140 },
141 {
142 name: "with custom scope",
143 constructorFn: NewAnyComponent,
144 opts: []DefinitionOption{
145 WithScope("anyScope"),

Callers

nothing calls this directly

Calls 12

WithNameFunction · 0.85
WithScopeFunction · 0.85
RegisterFunction · 0.85
ConditionalMethod · 0.80
ConstructorMethod · 0.80
LenMethod · 0.80
ConditionsMethod · 0.80
RunMethod · 0.65
DefinitionMethod · 0.65
NameMethod · 0.65
ScopeMethod · 0.65
TypeMethod · 0.45

Tested by

no test coverage detected