forked from getblank/wango
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg_test.go
50 lines (45 loc) · 1.12 KB
/
msg_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
package wango
import (
"strconv"
"testing"
)
func TestCreateMessage(t *testing.T) {
msg, err := createMessage(1, "com", "wango", 2)
if err != nil {
t.Fatal(err)
}
expected := `[1,"com","wango",2]`
if string(msg) != expected {
t.Fatal("Invalid createMessage", string(msg), "!=", expected)
}
}
func TestCreateHeartbeatEvent(t *testing.T) {
msg, err := createHeartbeatEvent(1)
if err != nil {
t.Fatal(err)
}
expected := `[` + strconv.Itoa(msgHeartbeat) + `,1]`
if string(msg) != expected {
t.Fatal("Invalid createHeartbeatEvent", string(msg), "!=", expected)
}
}
func TestCreateHeartbeatTxtEvent(t *testing.T) {
msg, err := createHeartbeatTxtEvent(1)
if err != nil {
t.Fatal(err)
}
expected := `["HB",1]`
if string(msg) != expected {
t.Fatal("Invalid createHeartbeatEvent", string(msg), "!=", expected)
}
}
func TestCreateWelcomeMessage(t *testing.T) {
msg, err := createWelcomeMessage("1")
if err != nil {
t.Fatal(err)
}
expected := `["` + msgIntTypes[msgWelcome] + `","1",1,"` + identity + `"]`
if string(msg) != expected {
t.Fatal("Invalid createWelcomeMessage", string(msg), "!=", expected)
}
}