-
Notifications
You must be signed in to change notification settings - Fork 1
/
testing_test.go
55 lines (45 loc) · 1.44 KB
/
testing_test.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
49
50
51
52
53
54
55
package workflow_test
import (
"context"
"testing"
"github.com/luno/jettison/jtest"
"github.com/luno/workflow"
"github.com/luno/workflow/adapters/memrecordstore"
"github.com/luno/workflow/adapters/memrolescheduler"
"github.com/luno/workflow/adapters/memstreamer"
"github.com/luno/workflow/adapters/memtimeoutstore"
)
func TestRequireForCircularStatus(t *testing.T) {
type Counter struct {
Count int
}
b := workflow.NewBuilder[Counter, status]("circular flow")
b.AddStep(StatusStart, func(ctx context.Context, r *workflow.Record[Counter, status]) (status, error) {
r.Object.Count += 1
return StatusMiddle, nil
}, StatusMiddle)
b.AddStep(StatusMiddle, func(ctx context.Context, r *workflow.Record[Counter, status]) (status, error) {
if r.Object.Count < 2 {
return StatusStart, nil
}
r.Object.Count += 1
return StatusEnd, nil
}, StatusStart, StatusEnd)
wf := b.Build(
memstreamer.New(),
memrecordstore.New(),
memtimeoutstore.New(),
memrolescheduler.New(),
)
ctx := context.Background()
wf.Run(ctx)
t.Cleanup(wf.Stop)
fid := "10298309123"
_, err := wf.Trigger(ctx, fid, StatusStart)
jtest.RequireNil(t, err)
workflow.Require(t, wf, fid, StatusStart, Counter{Count: 0})
workflow.Require(t, wf, fid, StatusMiddle, Counter{Count: 1})
workflow.Require(t, wf, fid, StatusStart, Counter{Count: 1})
workflow.Require(t, wf, fid, StatusMiddle, Counter{Count: 2})
workflow.Require(t, wf, fid, StatusEnd, Counter{Count: 3})
}