-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_many_labels.go
76 lines (62 loc) · 1.82 KB
/
get_many_labels.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package testcases
import (
"context"
"time"
"github.com/makasim/flowstate"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
)
func GetManyLabels(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),
)))
stateCtx.Current.SetLabel(`bar`, `barVal`)
require.NoError(t, e.Do(flowstate.Commit(
flowstate.Pause(stateCtx),
)))
require.NoError(t, e.Do(flowstate.Commit(
flowstate.Pause(&flowstate.StateCtx{
Current: flowstate.State{
ID: "anotherTID",
Labels: map[string]string{
`foo`: `barVal`,
},
},
}),
)))
cmd := flowstate.GetManyByLabels(map[string]string{
`foo`: `fooVal`,
})
require.NoError(t, e.Do(cmd))
res, err := cmd.Result()
require.NoError(t, err)
require.Len(t, res.States, 2)
require.False(t, res.More)
actStates := res.States
require.Equal(t, flowstate.StateID(`aTID`), actStates[0].ID)
require.Equal(t, int64(1), actStates[0].Rev)
require.Equal(t, `paused`, actStates[0].Transition.Annotations[`flowstate.state`])
require.Equal(t, `fooVal`, actStates[0].Labels[`foo`])
require.Equal(t, flowstate.StateID(`aTID`), actStates[1].ID)
require.Equal(t, int64(2), actStates[1].Rev)
require.Equal(t, `paused`, actStates[1].Transition.Annotations[`flowstate.state`])
require.Equal(t, `fooVal`, actStates[1].Labels[`foo`])
require.Equal(t, `barVal`, actStates[1].Labels[`bar`])
}