-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathmessage_test.go
More file actions
94 lines (81 loc) · 2.05 KB
/
message_test.go
File metadata and controls
94 lines (81 loc) · 2.05 KB
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
package socketio
import (
"testing"
)
func TestParseMessageInvalidType(t *testing.T) {
_, err := parseMessage("a::")
if err == nil {
t.Errorf("Invaild message type was not detected")
}
}
func TestParseMessageShort(t *testing.T) {
_, err := parseMessage("0:")
if err == nil {
t.Errorf("Invaild message was not detected")
}
}
func TestParseMessageData(t *testing.T) {
msg, _ := parseMessage("4:::This is data")
if msg.Data != "This is data" {
t.Errorf("Message data was not parsed correctly")
}
}
func TestNewDisconnect(t *testing.T) {
m := NewDisconnect()
if m.String() != "0::" {
t.Errorf("Disconnect message string")
}
}
func TestNewConnect(t *testing.T) {
endpoint := NewEndpoint("/path", "Key=Value")
m := NewConnect(endpoint)
if m.String() != "1::/path?Key=Value" {
t.Errorf("Connect message string")
}
}
func TestNewHeartbeat(t *testing.T) {
m := NewHeartbeat()
if m.String() != "2::" {
t.Errorf("Connect message string")
}
}
func TestNewMessage(t *testing.T) {
endpoint := NewEndpoint("/path", "Key=Value")
m := NewMessageMsg(endpoint, "This is a test message")
if m.String() != "3::/path?Key=Value:This is a test message" {
t.Errorf("Connect message string")
}
}
func TestNewJSONMessage(t *testing.T) {
endpoint := NewEndpoint("/path", "Key=Value")
m := NewJSONMessage(endpoint, "This is JSON data")
if m.String() != "4::/path?Key=Value:This is JSON data" {
t.Errorf("Error NewJSONMessage")
}
}
func TestNewEvent(t *testing.T) {
endpoint := NewEndpoint("/path", "Key=Value")
m := NewEvent(endpoint, "name", "args")
if m.String() != "5::/path?Key=Value:args" {
t.Errorf("Error NewEvent()")
}
}
func TestNewACK(t *testing.T) {
m := NewACK("data")
if m.String() != "6:::data" {
t.Errorf("Error NewACK")
}
}
func TestNewError(t *testing.T) {
endpoint := NewEndpoint("/path", "Key=Value")
m := NewError(endpoint, "reason", "advice")
if m.String() != "7::/path?Key=Value:reason+advice" {
t.Errorf("Error NewError")
}
}
func TestNewNoop(t *testing.T) {
m := NewNoop()
if m.String() != "8::" {
t.Errorf("Error NewNoop")
}
}