-
Notifications
You must be signed in to change notification settings - Fork 112
/
logger_test.go
63 lines (60 loc) · 1.24 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
package main
import (
"testing"
"github.com/go-kit/log/level"
"github.com/stretchr/testify/require"
)
func TestLoggerConfig_Validate(t *testing.T) {
type fields struct {
LogLevel string
LogFormat string
}
tests := []struct {
name string
fields fields
wantFunc func(t *testing.T, err error)
}{
{
name: "bad log level",
fields: fields{
LogLevel: "notALogLevel",
LogFormat: "logfmt",
},
wantFunc: func(t *testing.T, err error) {
require.ErrorIs(t, err, level.ErrInvalidLevelString, "log level should be invalid")
},
},
{
name: "bad log format",
fields: fields{
LogLevel: "debug",
LogFormat: "notALogFormat",
},
wantFunc: func(t *testing.T, err error) {
require.ErrorIs(t, err, errInvalidLogFormatFlag, "log format flag should be invalid")
},
},
{
name: "good config",
fields: fields{
LogLevel: "debug",
LogFormat: "json",
},
wantFunc: func(t *testing.T, err error) {
require.NoError(t, err)
},
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
lc := &LoggerConfig{
LogLevel: tt.fields.LogLevel,
LogFormat: tt.fields.LogFormat,
}
err := lc.Validate()
tt.wantFunc(t, err)
})
}
}