-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwo_consequent_nodes.go
48 lines (38 loc) · 1.19 KB
/
two_consequent_nodes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package testcases
import (
"context"
"time"
"github.com/makasim/flowstate"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
)
func TwoConsequentNodes(t TestingT, d flowstate.Doer, fr FlowRegistry) {
defer goleak.VerifyNone(t, goleak.IgnoreCurrent())
trkr := &Tracker{}
fr.SetFlow("first", flowstate.FlowFunc(func(stateCtx *flowstate.StateCtx, e flowstate.Engine) (flowstate.Command, error) {
Track(stateCtx, trkr)
return flowstate.Transit(stateCtx, `second`), nil
}))
fr.SetFlow("second", flowstate.FlowFunc(func(stateCtx *flowstate.StateCtx, e flowstate.Engine) (flowstate.Command, error) {
Track(stateCtx, trkr)
return flowstate.End(stateCtx), nil
}))
l, _ := NewTestLogger(t)
e, err := flowstate.NewEngine(d, l)
require.NoError(t, err)
defer func() {
sCtx, sCtxCancel := context.WithTimeout(context.Background(), time.Second*5)
defer sCtxCancel()
require.NoError(t, e.Shutdown(sCtx))
}()
stateCtx := &flowstate.StateCtx{
Current: flowstate.State{
ID: "aTID",
Rev: 0,
},
}
require.NoError(t, e.Do(flowstate.Transit(stateCtx, `first`)))
err = e.Execute(stateCtx)
require.NoError(t, err)
require.Equal(t, []string{`first`, `second`}, trkr.Visited())
}