-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrequest_test.go
107 lines (83 loc) · 1.6 KB
/
request_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
package chat
import (
"chat/service"
"fmt"
"testing"
)
func TestHandleRequest(t *testing.T) {
sendID := "send_id_123"
acceptID := "accept_id_456"
cli := &service.Client{}
var msg []byte
var err error
msg = []byte(fmt.Sprintf(`{
"id": "%s",
"content": "系统消息内容",
"type": 0,
"to": ["%s"]
}`, sendID, acceptID))
err = service.DispatchRequest(cli, msg)
if err != nil {
t.Error(err)
}
msg = []byte(`{
"id": "send_id",
"content": "广播消息内容",
"type": 1,
"to": ["accept_id"]
}`)
err = service.DispatchRequest(cli, msg)
if err != nil {
t.Error(err)
}
msg = []byte(`{
"id": "send_id",
"content": "心跳消息内容",
"type": 2,
"to": ["accept_id"]
}`)
err = service.DispatchRequest(cli, msg)
if err != nil {
t.Error(err)
}
msg = []byte(`{
"id": "send_id",
"content": "上线通知消息内容",
"type": 3,
"to": ["accept_id"]
}`)
err = service.DispatchRequest(cli, msg)
if err != nil {
t.Error(err)
}
msg = []byte(fmt.Sprintf(`{
"id": "%s",
"content": "下线通知消息内容",
"type": 4,
"to": ["%s"]
}`, sendID, acceptID))
err = service.DispatchRequest(cli, msg)
if err != nil {
t.Error(err)
}
msg = []byte(fmt.Sprintf(`{
"id": "%s",
"content": "服务断开链接通知",
"type": 5,
"to": ["%s"]
}`, sendID, acceptID))
err = service.DispatchRequest(cli, msg)
if err != nil {
t.Error(err)
}
msg = []byte(fmt.Sprintf(`{
"id": "%s",
"content": "注册事件消息",
"type": 6,
"to": ["%s"]
}`, sendID, acceptID))
err = service.DispatchRequest(cli, msg)
if err != nil {
t.Error(err)
}
}