-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_one_by_id_and_rev.go
51 lines (40 loc) · 1.21 KB
/
get_one_by_id_and_rev.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
package testcases
import (
"context"
"time"
"github.com/makasim/flowstate"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"
)
func GetOneByIDAndRev(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",
},
}
stateCtx.Current.SetAnnotation("v", "1")
require.NoError(t, e.Do(flowstate.Commit(
flowstate.CommitStateCtx(stateCtx),
)))
expectedStateCtx := stateCtx.CopyTo(&flowstate.StateCtx{})
stateCtx.Current.SetAnnotation("v", "2")
require.NoError(t, e.Do(flowstate.Commit(
flowstate.CommitStateCtx(stateCtx),
)))
stateCtx.Current.SetAnnotation("v", "3")
require.NoError(t, e.Do(flowstate.Commit(
flowstate.CommitStateCtx(stateCtx),
)))
foundStateCtx := &flowstate.StateCtx{}
require.NoError(t, e.Do(flowstate.GetByID(foundStateCtx, `aTID`, expectedStateCtx.Committed.Rev)))
require.Equal(t, expectedStateCtx, foundStateCtx)
}