-
Notifications
You must be signed in to change notification settings - Fork 0
/
message_test.go
56 lines (46 loc) · 913 Bytes
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package panda
import (
"fmt"
"testing"
)
func TestMarshal(t *testing.T) {
msg := &messageStruct{
Channel: "sth",
Message: "My message",
}
msgByte, err := msg.marshal()
if err != nil {
t.Error(err)
}
fmt.Println(string(msgByte))
messageInstance, err := unmarshalMsg(msgByte)
if err != nil {
t.Error(err)
}
if msg.Channel != messageInstance.Channel || msg.Message != messageInstance.Message {
t.Fail()
}
}
func TestUnmarshal(t *testing.T) {
msgStr := `{
"msgType": 0,
"channel": "chat",
"message": "This is a test message."
}`
msgType := 0
m := "This is a test message."
ch := "chat"
msg, err := unmarshalMsg([]byte(msgStr))
if err != nil {
t.Error(err)
}
if msg.Message != m {
t.Error("Message did not match")
}
if msg.Channel != ch {
t.Error("Channel did not match")
}
if msg.MsgType != MessageType(msgType) {
t.Error("Message type did not match")
}
}