-
Notifications
You must be signed in to change notification settings - Fork 141
/
message_test.go
42 lines (37 loc) · 1.06 KB
/
message_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
package lhttp
var message = "LHTTP/1.0 CHAT\r\ncontent-type:json\r\ncontent-length:10\r\n\r\njsonbody"
/*
func TestParseUnparse(t *testing.T) {
//parse
w := buildMessage(message)
if w.command != "CHAT" {
t.Errorf("command error:%s", w.command)
}
if w.body != "jsonbody" {
t.Errorf("error body:%s", w.body)
}
if v, ok := w.headers["content-type"]; ok {
if v != "json" {
t.Errorf("error head value:%s", w.headers["content-type"])
}
} else {
t.Errorf("error key")
}
if v, ok := w.headers["content-length"]; ok {
if v != "10" {
t.Errorf("error head value:%s", w.headers["content-length"])
}
} else {
t.Errorf("error key")
}
//unparse
req := &WsHandler{message: w}
req.Send("hello")
if string(req.message.message) != "LHTTP/1.0 CHAT\r\ncontent-length:10\r\ncontent-type:json\r\n\r\nhello" {
t.Errorf("combine message error:%s", string(req.message.message))
}
if req.message.serializeMessage() != "LHTTP/1.0 CHAT\r\ncontent-length:10\r\ncontent-type:json\r\n\r\nhello" {
t.Errorf("serializeMessage error:%s", req.message.serializeMessage)
}
}
*/