-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogger_test.go
131 lines (95 loc) · 3.17 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package recording
import (
"testing"
"time"
"github.com/echocat/slf4g/fields"
"github.com/echocat/slf4g/level"
log "github.com/echocat/slf4g"
"github.com/echocat/slf4g/internal/test/assert"
)
func Test_NewLogger(t *testing.T) {
actual := NewLogger()
assert.ToBeNotNil(t, actual)
assert.ToBeNotNil(t, actual.CoreLogger)
assert.ToBeNotNil(t, actual.Logger)
wrapped := log.UnwrapCoreLogger(actual.Logger)
assert.ToBeSame(t, actual.CoreLogger, wrapped)
}
func Test_Logger_GetName_empty(t *testing.T) {
instance := NewLogger()
actual := instance.GetName()
assert.ToBeEqual(t, RootLoggerName, actual)
}
func Test_Logger_GetName_configured(t *testing.T) {
instance := NewLogger()
instance.Name = "foo"
actual := instance.GetName()
assert.ToBeEqual(t, "foo", actual)
}
func Test_Logger_GetProvider_empty(t *testing.T) {
instance := NewLogger()
actual := instance.GetProvider()
assert.ToBeSame(t, log.GetProvider(), actual)
}
func Test_Logger_GetProvider_configured(t *testing.T) {
instance := NewLogger()
instance.Provider = NewProvider()
actual := instance.GetProvider()
assert.ToBeSame(t, instance.Provider, actual)
}
func Test_Logger_IsLevelEnabled(t *testing.T) {
instance := NewLogger()
assert.ToBeEqual(t, false, instance.IsLevelEnabled(level.Debug))
assert.ToBeEqual(t, true, instance.IsLevelEnabled(level.Info))
assert.ToBeEqual(t, true, instance.IsLevelEnabled(level.Warn))
instance.SetLevel(level.Warn)
assert.ToBeEqual(t, false, instance.IsLevelEnabled(level.Debug))
assert.ToBeEqual(t, false, instance.IsLevelEnabled(level.Info))
assert.ToBeEqual(t, true, instance.IsLevelEnabled(level.Warn))
}
func Test_Logger_LogEvent(t *testing.T) {
instance := NewLogger()
instance.Provider = NewProvider()
givenEvent := instance.NewEvent(level.Warn, nil).
With("timestamp", time.Now()).
With("logger", "foo")
expected := givenEvent
assert.ToBeEqual(t, 0, instance.Len())
instance.Log(givenEvent, 666)
assert.ToBeEqual(t, 1, instance.Len())
assert.ToBeEqual(t, true, instance.MustContains(expected))
}
func Test_Logger_NewEvent(t *testing.T) {
instance := NewLogger()
instance.Provider = NewProvider()
assert.ToBeEqual(t, &event{
provider: instance.Provider,
fields: fields.Empty(),
level: level.Fatal,
}, instance.NewEvent(level.Fatal, nil))
assert.ToBeEqual(t, &event{
provider: instance.Provider,
fields: fields.WithAll(map[string]interface{}{"foo": "bar"}),
level: level.Fatal,
}, instance.NewEvent(level.Fatal, map[string]interface{}{"foo": "bar"}))
}
func Test_Logger_NewEventWithFields(t *testing.T) {
instance := NewLogger()
instance.Provider = NewProvider()
assert.ToBeEqual(t, &event{
provider: instance.Provider,
fields: fields.Empty(),
level: level.Fatal,
}, instance.NewEventWithFields(level.Fatal, nil))
assert.ToBeEqual(t, &event{
provider: instance.Provider,
fields: fields.With("foo", "bar"),
level: level.Fatal,
}, instance.NewEventWithFields(level.Fatal, fields.With("foo", "bar")))
}
func Test_Logger_Accepts(t *testing.T) {
instance := NewLogger()
instance.Provider = NewProvider()
assert.ToBeEqual(t, false, instance.Accepts(nil))
assert.ToBeEqual(t, true, instance.Accepts(&event{}))
}