Newer
Older
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
package server
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestNewIdleState(t *testing.T) {
tests := []struct {
name string
fsm *FSM2
expected *idleState
}{
{
name: "Test #1",
fsm: &FSM2{},
expected: &idleState{
fsm: &FSM2{},
},
},
}
for _, test := range tests {
res := newIdleState(test.fsm)
assert.Equalf(t, test.expected, res, "Test: %s", test.name)
}
}
func TestStart(t *testing.T) {
tests := []struct {
name string
state *idleState
expected *idleState
}{
{
name: "Test #1",
state: &idleState{
fsm: &FSM2{
connectRetryCounter: 5,
connectRetryTimer: time.NewTimer(time.Second * 20),
},
newStateReason: "Foo Bar",
},
expected: &idleState{
fsm: &FSM2{
connectRetryCounter: 0,
connectRetryTimer: time.NewTimer(time.Second * 20),
},
newStateReason: "Foo Bar",
},
},
}
for _, test := range tests {
if !test.expected.fsm.connectRetryTimer.Stop() {
<-test.expected.fsm.connectRetryTimer.C
}
test.state.start()
assert.Equalf(t, test.expected, test.state, "Test: %s", test.name)
}
}