-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlog_test.go
97 lines (90 loc) · 1.83 KB
/
log_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
package cmd_test
import (
"testing"
"github.com/hamba/cmd/v2"
"github.com/stretchr/testify/require"
"github.com/urfave/cli/v2"
)
func TestNewLogger(t *testing.T) {
tests := []struct {
name string
lvl string
format string
tags *cli.StringSlice
wantErr require.ErrorAssertionFunc
}{
{
name: "json format",
lvl: "info",
format: "json",
tags: cli.NewStringSlice(),
wantErr: require.NoError,
},
{
name: "logfmt format",
lvl: "info",
format: "logfmt",
tags: cli.NewStringSlice(),
wantErr: require.NoError,
},
{
name: "console format",
lvl: "info",
format: "console",
tags: cli.NewStringSlice(),
wantErr: require.NoError,
},
{
name: "no format",
lvl: "",
format: "json",
tags: cli.NewStringSlice(),
wantErr: require.NoError,
},
{
name: "invalid format",
lvl: "info",
format: "invalid",
tags: cli.NewStringSlice(),
wantErr: require.NoError,
},
{
name: "valid Level",
lvl: "info",
format: "",
tags: cli.NewStringSlice(),
wantErr: require.NoError,
},
{
name: "invalid Level",
lvl: "invalid",
format: "json",
tags: cli.NewStringSlice(),
wantErr: require.Error,
},
{
name: "tags",
lvl: "info",
format: "json",
tags: cli.NewStringSlice("a=b"),
wantErr: require.NoError,
},
{
name: "invalid tags",
lvl: "info",
format: "json",
tags: cli.NewStringSlice("single"),
wantErr: require.Error,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c, fs := newTestContext()
fs.String(cmd.FlagLogLevel, tt.lvl, "doc")
fs.String(cmd.FlagLogFormat, tt.format, "doc")
fs.Var(tt.tags, cmd.FlagLogCtx, "doc")
_, err := cmd.NewLogger(c)
tt.wantErr(t, err)
})
}
}