-
Notifications
You must be signed in to change notification settings - Fork 26
/
handler_test.go
47 lines (35 loc) · 1.34 KB
/
handler_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
package slog_test
import (
"testing"
"github.com/gookit/goutil/testutil/assert"
"github.com/gookit/slog"
)
func TestNewLvFormatter(t *testing.T) {
lf := slog.NewLvFormatter(slog.InfoLevel)
assert.True(t, lf.IsHandling(slog.ErrorLevel))
assert.True(t, lf.IsHandling(slog.InfoLevel))
assert.False(t, lf.IsHandling(slog.DebugLevel))
lf.SetMaxLevel(slog.DebugLevel)
assert.True(t, lf.IsHandling(slog.DebugLevel))
}
func TestNewLvsFormatter(t *testing.T) {
lf := slog.NewLvsFormatter([]slog.Level{slog.InfoLevel, slog.ErrorLevel})
assert.True(t, lf.IsHandling(slog.InfoLevel))
assert.False(t, lf.IsHandling(slog.DebugLevel))
lf.SetLimitLevels([]slog.Level{slog.InfoLevel, slog.ErrorLevel, slog.DebugLevel})
assert.True(t, lf.IsHandling(slog.DebugLevel))
}
func TestLevelFormatting(t *testing.T) {
lf := slog.NewMaxLevelFormatting(slog.InfoLevel)
assert.True(t, lf.IsHandling(slog.InfoLevel))
assert.False(t, lf.IsHandling(slog.TraceLevel))
// use levels
lf = slog.NewLevelsFormatting([]slog.Level{slog.InfoLevel, slog.ErrorLevel})
assert.True(t, lf.IsHandling(slog.InfoLevel))
assert.True(t, lf.IsHandling(slog.ErrorLevel))
assert.False(t, lf.IsHandling(slog.TraceLevel))
// test level mode
assert.Eq(t, "list", slog.LevelModeList.String())
assert.Eq(t, "max", slog.LevelModeMax.String())
assert.Eq(t, "unknown", slog.LevelMode(9).String())
}