-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch_since_latest.go
55 lines (46 loc) · 1.32 KB
/
watch_since_latest.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 testcases
import (
"context"
"time"
"github.com/makasim/flowstate"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
)
func WatchSinceLatest(t TestingT, d flowstate.Doer, _ FlowRegistry) {
defer goleak.VerifyNone(t, goleak.IgnoreCurrent())
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",
Labels: map[string]string{
`foo`: `fooVal`,
},
},
}
require.NoError(t, e.Do(flowstate.Commit(
flowstate.Pause(stateCtx),
)))
require.NoError(t, e.Do(flowstate.Commit(
flowstate.Pause(stateCtx),
)))
require.NoError(t, e.Do(flowstate.Commit(
flowstate.Pause(stateCtx),
)))
w := flowstate.NewWatcher(e, flowstate.GetManyByLabels(map[string]string{
`foo`: `fooVal`,
}).WithSinceLatest())
defer w.Close()
actStates := watchCollectStates(t, w, 1)
require.Len(t, actStates, 1)
require.Equal(t, flowstate.StateID(`aTID`), actStates[0].ID)
require.Equal(t, int64(3), actStates[0].Rev)
require.Equal(t, `paused`, actStates[0].Transition.Annotations[`flowstate.state`])
require.Equal(t, `fooVal`, actStates[0].Labels[`foo`])
}