MCPcopy Create free account
hub / github.com/ForestHubAI/edge-agents / TestSetVariable_Execute

Function TestSetVariable_Execute

go/engine/node/setvariable_test.go:20–97  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

18)
19
20func TestSetVariable_Execute(t *testing.T) {
21 t.Run("evaluates literal expression and writes to scope", func(t *testing.T) {
22 s, err := engine.NewMainScope([]workflowapi.Variable{
23 {Uid: "x", DataType: workflowapi.Int},
24 })
25 require.NoError(t, err)
26
27 n := NewSetVariable("set1",
28 workflowapi.Reference{SrcId: engine.SrcDeclared, VarId: "x"},
29 workflowapi.Expression{Expression: "42", DataType: workflowapi.Int},
30 )
31
32 next, err := n.Execute(context.Background(), s)
33 require.NoError(t, err)
34 assert.Equal(t, engine.StateIdle, next)
35
36 v, err := s.Resolve(workflowapi.Reference{SrcId: engine.SrcDeclared, VarId: "x"})
37 require.NoError(t, err)
38 assert.Equal(t, expr.IntVal(42), v)
39 })
40
41 t.Run("eval error is wrapped with node id", func(t *testing.T) {
42 s, err := engine.NewMainScope(nil)
43 require.NoError(t, err)
44
45 n := NewSetVariable("setBad",
46 workflowapi.Reference{SrcId: engine.SrcDeclared, VarId: "x"},
47 workflowapi.Expression{
48 Expression: "${}",
49 DataType: workflowapi.Int,
50 References: []workflowapi.Reference{{SrcId: "missing", VarId: "y"}},
51 },
52 )
53 _, err = n.Execute(context.Background(), s)
54 require.Error(t, err)
55 assert.Contains(t, err.Error(), "set_variable setBad")
56 })
57
58 t.Run("transitions to wired target", func(t *testing.T) {
59 s, err := engine.NewMainScope([]workflowapi.Variable{
60 {Uid: "x", DataType: workflowapi.Int},
61 })
62 require.NoError(t, err)
63
64 n := NewSetVariable("set2",
65 workflowapi.Reference{SrcId: engine.SrcDeclared, VarId: "x"},
66 workflowapi.Expression{Expression: "1", DataType: workflowapi.Int},
67 )
68 require.NoError(t, n.AddTransition(engine.PortCtrl, engine.Transition{TargetID: "next"}))
69
70 next, err := n.Execute(context.Background(), s)
71 require.NoError(t, err)
72 assert.Equal(t, "next", next)
73 })
74
75 t.Run("expression referencing scope is evaluated", func(t *testing.T) {
76 s, err := engine.NewMainScope([]workflowapi.Variable{
77 {Uid: "src", DataType: workflowapi.Int, InitialValue: float64(10)},

Callers

nothing calls this directly

Calls 6

ExecuteMethod · 0.95
NewSetVariableFunction · 0.85
ResolveMethod · 0.65
AddTransitionMethod · 0.65
RunMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected