-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstate_test.go
More file actions
64 lines (59 loc) · 1.53 KB
/
Copy pathstate_test.go
File metadata and controls
64 lines (59 loc) · 1.53 KB
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
package trexec
import (
"testing"
)
func TestStateString(t *testing.T) {
tests := []struct {
state State
want string
}{
{StateCreated, "created"},
{StateStarting, "starting"},
{StateRunning, "running"},
{StateStopping, "stopping"},
{StateKilling, "killing"},
{StateDone, "done"},
{State(99), "unknown(99)"},
}
for _, tt := range tests {
if got := tt.state.String(); got != tt.want {
t.Errorf("State(%d).String() = %q, want %q", tt.state, got, tt.want)
}
}
}
func TestCanTransition(t *testing.T) {
valid := []struct {
from, to State
}{
{StateCreated, StateStarting},
{StateStarting, StateRunning},
{StateStarting, StateDone},
{StateRunning, StateStopping},
{StateRunning, StateDone},
{StateStopping, StateKilling},
{StateStopping, StateDone},
{StateKilling, StateDone},
}
for _, tt := range valid {
if !canTransition(tt.from, tt.to) {
t.Errorf("canTransition(%s, %s) = false, want true", tt.from, tt.to)
}
}
invalid := []struct {
from, to State
}{
{StateCreated, StateRunning}, // skip Starting
{StateCreated, StateDone}, // skip everything
{StateRunning, StateKilling}, // skip Stopping
{StateDone, StateCreated}, // terminal
{StateDone, StateRunning}, // terminal
{StateKilling, StateStopping}, // backwards
{StateStopping, StateRunning}, // backwards
{StateStarting, StateStopping}, // skip Running
}
for _, tt := range invalid {
if canTransition(tt.from, tt.to) {
t.Errorf("canTransition(%s, %s) = true, want false", tt.from, tt.to)
}
}
}