-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_test.go
70 lines (56 loc) · 1.16 KB
/
event_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package ga
import (
"bytes"
"testing"
"time"
)
func Test_Event_WriteTo(t *testing.T) {
e := &Event{}
e.Set("alpha", "one")
e.Set("beta", "two")
buf := bytes.NewBuffer(nil)
_, err := e.WriteTo(buf)
if err != nil {
t.Fatal(err)
}
if buf.String() != "alpha=one&beta=two" {
t.Fatal(buf.String())
}
}
func Test_Event_WriteTo_WithEscaping(t *testing.T) {
e := &Event{}
e.Set("alpha", "@lpha")
e.Set("beta", "&eta")
buf := bytes.NewBuffer(nil)
_, err := e.WriteTo(buf)
if err != nil {
t.Fatal(err)
}
if buf.String() != "alpha=%40lpha&beta=%26eta" {
t.Fatal(buf.String())
}
}
func Test_Events_WriteTo_WithEscaping(t *testing.T) {
empty := Event{}
a := Event{}
a.Set("alpha", "@lpha")
a.Set("beta", "&eta")
a.Set("delta", "")
b := Event{}
b.Set("one", "*ne")
b.Set("two", "!wo")
l := events{
event{reportedAt: time.Now(), e: empty},
event{reportedAt: time.Now(), e: a},
event{reportedAt: time.Now(), e: empty},
event{reportedAt: time.Now(), e: b},
}
buf := bytes.NewBuffer(nil)
_, err := l.WriteTo(buf)
if err != nil {
t.Fatal(err)
}
if buf.String() != "alpha=%40lpha&beta=%26eta\none=%2Ane&two=%21wo" {
t.Fatal(buf.String())
}
}