-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrecord_test.go
53 lines (50 loc) · 1.1 KB
/
record_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
package ligno
import (
"encoding/json"
"testing"
"time"
)
func TestCreateRecordEmpty(t *testing.T) {
_ = Record{}
}
func TestSerializeRecordToJSON(t *testing.T) {
recordTime := time.Now().UTC()
testData := []Record{
{
Time: recordTime,
Level: INFO,
Message: "some message",
Context: Ctx{"a": "b"},
Logger: nil,
},
{
Time: recordTime,
Level: ERROR,
Context: Ctx{},
Logger: GetLogger(""),
},
}
for _, r := range testData {
marshaled, err := json.Marshal(r)
if err != nil {
t.Fatal(err)
}
var unmarshaled map[string]interface{}
json.Unmarshal(marshaled, &unmarshaled)
if _, ok := unmarshaled["time"]; !ok {
t.Error("time not found in serialized JSON.")
}
if _, ok := unmarshaled["level"]; !ok {
t.Error("level not found in serialzied JSON.")
}
if _, ok := unmarshaled["message"]; !ok {
t.Error("message not found in serialized JSON.")
}
if _, ok := unmarshaled["context"]; !ok {
t.Error("context not found in serialized JSON.")
}
if _, ok := unmarshaled["logger"]; ok {
t.Error("logger found and was not expected.")
}
}
}