-
Notifications
You must be signed in to change notification settings - Fork 0
/
zmey_test.go
67 lines (47 loc) · 1.36 KB
/
zmey_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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package zmey
import (
"testing"
"github.com/stretchr/testify/assert"
)
type DummyProcess struct{}
func (DummyProcess) Init(
func(to int, payload interface{}),
func(payload interface{}),
func(payload interface{}),
func(error),
) {
}
func (DummyProcess) ReceiveNet(int, interface{}) {}
func (DummyProcess) ReceiveCall(interface{}) {}
func (DummyProcess) Tick(uint) {}
func TestSetProcess(t *testing.T) {
z := NewZmey(&Config{})
assert.Equal(t, map[int]*pack{}, z.packs)
assert.Equal(t, []int{}, z.pids)
z.SetProcess(5, DummyProcess{})
assert.Equal(t, 1, len(z.packs))
assert.Equal(t, []int{5}, z.pids)
z.SetProcess(3, DummyProcess{})
z.SetProcess(1, DummyProcess{})
z.SetProcess(8, DummyProcess{})
z.SetProcess(2, DummyProcess{})
z.SetProcess(6, DummyProcess{})
assert.Equal(t, 6, len(z.packs))
assert.Equal(t, []int{1, 2, 3, 5, 6, 8}, z.pids)
z.SetProcess(3, DummyProcess{})
assert.Equal(t, 6, len(z.packs))
assert.Equal(t, []int{1, 2, 3, 5, 6, 8}, z.pids)
z.SetProcess(2, nil)
assert.Equal(t, 5, len(z.packs))
assert.Equal(t, []int{1, 3, 5, 6, 8}, z.pids)
z.SetProcess(1, nil)
z.SetProcess(8, nil)
z.SetProcess(5, nil)
z.SetProcess(6, nil)
z.SetProcess(3, nil)
assert.Equal(t, 0, len(z.packs))
assert.Equal(t, []int{}, z.pids)
z.SetProcess(6, nil)
assert.Equal(t, 0, len(z.packs))
assert.Equal(t, []int{}, z.pids)
}