-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlog_test.go
74 lines (66 loc) · 1.29 KB
/
log_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
71
72
73
74
package gelf
import "testing"
func TestCreateMessage(t *testing.T) {
m := Create("hello")
if m.Version != "1.1" {
t.Log("Wrong version")
t.Fail()
}
if m.Host != "default" {
t.Log("Wrong default host")
t.Fail()
}
if m.ShortMessage != "hello" {
t.Log("Wrong message")
t.Fail()
}
if m.Timestamp == 0 {
t.Log("Missing Timestamp")
t.Fail()
}
if m.Level != 1 {
t.Log("Wrong level")
t.Fail()
}
}
func TestWithTimestamp(t *testing.T) {
m := Create("OK")
m.SetTimestamp(123)
if m.Timestamp != 123 {
t.Log("Wrong timestamp after set")
t.Fail()
}
}
func TestWithHost(t *testing.T) {
m := Create("OK")
m.SetHost("khongbiet")
if m.Host != "khongbiet" {
t.Log("Wrong host after set")
t.Fail()
}
}
func TestWithFullMessage(t *testing.T) {
m := Create("OK")
m.SetFullMessage("khongbiet")
if m.FullMessage != "khongbiet" {
t.Log("Wrong full message after set")
t.Fail()
}
}
func TestWithLevel(t *testing.T) {
m := Create("OK")
m.SetLevel(3)
if m.Level != 3 {
t.Log("Wrong level after set")
t.Fail()
}
}
func TestToJSON(t *testing.T) {
expect := `{"version":"1.1","host":"default","short_message":"OK","full_message":"","timestamp":145,"level":1}`
actual := Create("OK").SetTimestamp(145).ToJSON()
if expect != actual {
t.Log(expect)
t.Log(actual)
t.Fail()
}
}