MCPcopy Create free account
hub / github.com/cloudwego/eino / TestWorkflowWithNestedFieldMappings

Function TestWorkflowWithNestedFieldMappings

compose/workflow_test.go:268–656  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

266}
267
268func TestWorkflowWithNestedFieldMappings(t *testing.T) {
269 ctx := context.Background()
270
271 type structA struct {
272 F1 string
273 }
274
275 type structB struct {
276 F1 *structA
277 F2 map[string]any
278 F3 int
279 F4 any
280 F5 map[string]structA
281 F6 structA
282 }
283
284 t.Run("from struct.struct.field", func(t *testing.T) {
285 wf := NewWorkflow[*structB, string]()
286 wf.End().AddInput(START, FromFieldPath([]string{"F1", "F1"}))
287 r, err := wf.Compile(ctx)
288 assert.NoError(t, err)
289 out, err := r.Invoke(ctx, &structB{
290 F1: &structA{
291 F1: "hello",
292 },
293 })
294 assert.NoError(t, err)
295 assert.Equal(t, "hello", out)
296
297 wf = NewWorkflow[*structB, string]()
298 wf.End().AddInput(START, FromFieldPath([]string{"F1", "F2"}))
299 _, err = wf.Compile(ctx)
300 assert.ErrorContains(t, err, "has no field[F2]")
301 })
302
303 t.Run("to struct.(non-ptr)struct.field", func(t *testing.T) {
304 wf := NewWorkflow[string, *structB]()
305 wf.End().AddInput(START, ToFieldPath([]string{"F6", "F1"}))
306 r, err := wf.Compile(ctx)
307 assert.NoError(t, err)
308 out, err := r.Invoke(ctx, "hello")
309 assert.NoError(t, err)
310 assert.Equal(t, &structB{
311 F6: structA{
312 F1: "hello",
313 },
314 }, out)
315 })
316
317 t.Run("to map.(non-ptr)struct.field", func(t *testing.T) {
318 wf := NewWorkflow[string, map[string]structA]()
319 wf.End().AddInput(START, ToFieldPath([]string{"key", "F1"}))
320 r, err := wf.Compile(ctx)
321 assert.NoError(t, err)
322 out, err := r.Invoke(ctx, "hello")
323 assert.NoError(t, err)
324 assert.Equal(t, map[string]structA{
325 "key": {

Callers

nothing calls this directly

Calls 9

NewWorkflowFunction · 0.85
FromFieldPathFunction · 0.85
ToFieldPathFunction · 0.85
MapFieldPathsFunction · 0.85
AddInputMethod · 0.80
EndMethod · 0.80
RunMethod · 0.65
InvokeMethod · 0.65
CompileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…