-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions_test.go
85 lines (78 loc) · 1.67 KB
/
options_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
package log
import (
"bytes"
"io"
"os"
"testing"
"github.com/qdm12/log/internal/caller"
"github.com/stretchr/testify/assert"
)
func Test_Option(t *testing.T) {
t.Parallel()
testCases := map[string]struct {
initialSettings settings
option Option
expectedSettings settings
}{
"SetLevel": {
option: SetLevel(LevelInfo),
expectedSettings: settings{
level: levelPtr(LevelInfo),
},
},
"SetCallerFile": {
option: SetCallerFile(false),
expectedSettings: settings{
caller: caller.Settings{
File: boolPtr(false),
},
},
},
"SetCallerLine": {
option: SetCallerLine(true),
expectedSettings: settings{
caller: caller.Settings{
Line: boolPtr(true),
},
},
},
"SetCallerFunc": {
option: SetCallerFunc(true),
expectedSettings: settings{
caller: caller.Settings{
Func: boolPtr(true),
},
},
},
"SetTimeFormat": {
option: SetTimeFormat("123"),
expectedSettings: settings{
timeFormat: stringPtr("123"),
},
},
"SetWriters": {
option: SetWriters(os.Stdout, io.Discard),
expectedSettings: settings{
writers: []io.Writer{os.Stdout, io.Discard},
},
},
"AddWriters": {
initialSettings: settings{
writers: []io.Writer{bytes.NewBuffer(nil), io.Discard},
},
option: AddWriters(os.Stdout, io.Discard),
expectedSettings: settings{
writers: []io.Writer{bytes.NewBuffer(nil), io.Discard, os.Stdout},
},
},
}
for name, testCase := range testCases {
testCase := testCase
t.Run(name, func(t *testing.T) {
t.Parallel()
settings := testCase.initialSettings
testCase.option(&settings)
assert.Equal(t, testCase.expectedSettings, settings)
})
}
}