-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlocal_test.go
48 lines (34 loc) · 986 Bytes
/
local_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
package machine_test
import (
"fmt"
"testing"
"github.com/gophergala2016/machine"
"golang.org/x/net/context"
)
func state1(ctx context.Context, transitioner machine.Transitioner) {
fmt.Println("this is state 1")
transitioner.Next(state2)
}
func state2(ctx context.Context, transitioner machine.Transitioner) {
fmt.Println("this is state 2")
transitioner.Next(state3)
}
func state3(ctx context.Context, transitioner machine.Transitioner) {
fmt.Println("this is state 3")
transitioner.Done()
}
func TestLocalStateRun(t *testing.T) {
localMachine := machine.NewLocalMachine()
ctx := context.Background()
localMachine.Run(ctx, state1).Wait(0)
}
func state4(ctx context.Context, transitioner machine.Transitioner) {
fmt.Println("state 4")
transitioner.Fork(ctx, state1, state2, state3).Wait(0)
transitioner.Done()
}
func TestLocalStateFork(t *testing.T) {
localMachine := machine.NewLocalMachine()
ctx := context.Background()
localMachine.Run(ctx, state4)
}