-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
message_test.go
48 lines (37 loc) · 840 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
package sse
import "testing"
func TestEmptyMessage(t *testing.T) {
msg := Message{}
if msg.String() != "\n" {
t.Fatal("Message does not match.")
}
}
func TestDataMessage(t *testing.T) {
msg := Message{data: "test"}
if msg.String() != "data: test\n\n" {
t.Fatal("Message does not match.")
}
}
func TestMessage(t *testing.T) {
msg := Message{
"123",
"test",
"myevent",
10 * 1000,
}
if msg.String() != "id: 123\nretry: 10000\nevent: myevent\ndata: test\n\n" {
t.Fatal("Message does not match.")
}
}
func TestMultilineDataMessage(t *testing.T) {
msg := Message{data: "test\ntest"}
if msg.String() != "data: test\ndata: test\n\n" {
t.Fail()
}
}
func TestSpecialCharacterMessage(t *testing.T) {
msg := Message{data: "%x%o"}
if msg.String() != "data: %x%o\n\n" {
t.Fatal("Message does not match.")
}
}