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

Function TestConditionalLoader_Load

component/loader_test.go:76–145  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

74}
75
76func TestConditionalLoader_Load(t *testing.T) {
77 anyComponentDef, _ := MakeDefinition(NewAnyComponent)
78 require.NotNil(t, anyComponentDef)
79
80 anotherComponentDef, _ := MakeDefinition(NewAnotherComponent)
81 require.NotNil(t, anotherComponentDef)
82
83 testCases := []struct {
84 name string
85 ctx context.Context
86 container Container
87 components []*Component
88 wantErr error
89 wantTypes []reflect.Type
90 }{
91 {
92 name: "load component",
93 container: NewDefaultContainer(),
94 components: []*Component{
95 createComponent(anyComponentDef),
96 },
97 wantTypes: []reflect.Type{
98 reflect.TypeOf(&AnyComponent{}),
99 },
100 },
101 {
102 name: "skip component",
103 ctx: context.Background(),
104 container: NewDefaultContainer(),
105 components: []*Component{
106 createComponent(anyComponentDef, AnyCondition{matches: false}),
107 createComponent(anotherComponentDef),
108 },
109 wantTypes: []reflect.Type{
110 reflect.TypeOf(&AnotherComponent{}),
111 },
112 },
113 {
114 name: "already exists",
115 container: NewDefaultContainer(),
116 components: []*Component{
117 createComponent(anyComponentDef),
118 createComponent(anyComponentDef),
119 },
120 wantErr: fmt.Errorf("failed to register component \"anyComponent\": %s", ErrDefinitionAlreadyExists),
121 },
122 }
123
124 for _, tc := range testCases {
125 t.Run(tc.name, func(t *testing.T) {
126 // given
127 loader := NewConditionalLoader(tc.container, tc.components)
128
129 // when
130 err := loader.Load(tc.ctx)
131
132 // then
133 if tc.wantErr != nil {

Callers

nothing calls this directly

Calls 7

LoadMethod · 0.95
MakeDefinitionFunction · 0.85
NewDefaultContainerFunction · 0.85
createComponentFunction · 0.85
NewConditionalLoaderFunction · 0.85
RunMethod · 0.65
CanResolveTypeMethod · 0.65

Tested by

no test coverage detected