generated from logur/adapter-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger_test.go
52 lines (40 loc) · 1.06 KB
/
logger_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
package zerolog
import (
"bytes"
"encoding/json"
"strings"
"testing"
"github.com/rs/zerolog"
"logur.dev/logur"
"logur.dev/logur/conformance"
)
func TestLogger(t *testing.T) {
suite := conformance.TestSuite{
LoggerFactory: func(level logur.Level) (logur.Logger, conformance.TestLogger) {
var buf bytes.Buffer
logger := zerolog.New(&buf).Level(zerolog.Level(level - 1))
return New(logger), conformance.TestLoggerFunc(func() []logur.LogEvent {
lines := strings.Split(strings.TrimSuffix(buf.String(), "\n"), "\n")
events := make([]logur.LogEvent, len(lines))
for key, line := range lines {
var event map[string]interface{}
err := json.Unmarshal([]byte(line), &event)
if err != nil {
panic(err)
}
level, _ := logur.ParseLevel(strings.ToLower(event["level"].(string)))
msg := event["message"].(string)
delete(event, "level")
delete(event, "message")
events[key] = logur.LogEvent{
Line: msg,
Level: level,
Fields: event,
}
}
return events
})
},
}
suite.Run(t)
}