forked from googollee/go-socket.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacket_test.go
123 lines (122 loc) · 1.95 KB
/
packet_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package parser
var tests = []struct {
Name string
Header Header
Event string
Var []interface{}
Data [][]byte
}{
{"Empty",
Header{Connect, 0, false, "", ""},
"",
nil,
[][]byte{
[]byte("0"),
},
},
{"Data",
Header{Error, 0, false, "", ""},
"",
[]interface{}{"error"},
[][]byte{
[]byte("4[\"error\"]\n"),
},
},
{"BData",
Header{Event, 0, false, "", ""},
"msg",
[]interface{}{
&Buffer{Data: []byte{1, 2, 3}},
},
[][]byte{
[]byte("51-[\"msg\",{\"_placeholder\":true,\"num\":0}]\n"),
{1, 2, 3},
},
},
{"ID",
Header{Connect, 0, true, "", ""},
"",
nil,
[][]byte{
[]byte("00"),
},
},
{"IDData",
Header{Ack, 13, true, "", ""},
"",
[]interface{}{"error"},
[][]byte{
[]byte("313[\"error\"]\n"),
},
},
{"IDBData",
Header{Ack, 13, true, "", ""},
"",
[]interface{}{
&Buffer{
Data: []byte{1, 2, 3},
},
},
[][]byte{
[]byte("61-13[{\"_placeholder\":true,\"num\":0}]\n"),
{1, 2, 3},
},
},
{"Namespace",
Header{Disconnect, 0, false, "/woot", ""},
"",
nil,
[][]byte{
[]byte("1/woot"),
},
},
{"NamespaceData",
Header{Event, 0, false, "/woot", ""},
"msg",
[]interface{}{
1,
},
[][]byte{
[]byte("2/woot,[\"msg\",1]\n"),
},
},
{"NamespaceBData",
Header{Event, 0, false, "/woot", ""},
"msg",
[]interface{}{
&Buffer{Data: []byte{2, 3, 4}},
},
[][]byte{
[]byte("51-/woot,[\"msg\",{\"_placeholder\":true,\"num\":0}]\n"),
{2, 3, 4},
},
},
{"NamespaceID",
Header{Disconnect, 1, true, "/woot", ""},
"",
nil,
[][]byte{
[]byte("1/woot,1"),
},
},
{"NamespaceIDData",
Header{Event, 1, true, "/woot", ""},
"msg",
[]interface{}{
1,
},
[][]byte{
[]byte("2/woot,1[\"msg\",1]\n"),
},
},
{"NamespaceIDBData", Header{Event, 1, true, "/woot", ""},
"msg",
[]interface{}{
&Buffer{Data: []byte{2, 3, 4}},
},
[][]byte{
[]byte("51-/woot,1[\"msg\",{\"_placeholder\":true,\"num\":0}]\n"),
{2, 3, 4},
},
},
}