-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger_test.go
71 lines (60 loc) · 2.1 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
package GOgger_test
import (
GOgger "Gogger"
"testing"
)
type testWriter struct {
contents string }
// Write implements the io.Writer interface.
func (tw *testWriter) Write(p []byte) (n int, err error) {
tw.contents = tw.contents + string(p)
return len(p), nil }
const (
debugMessage = "Why write I still all one, ever the same,"
infoMessage = "And keep invention in a noted weed,"
warnMessage = "Then take the chance by the thorns"
errorMessage = "That every word doth almost tell my name,"
fatalMessage = "Why thou"
)
func TestLogger_DebugfInforfErrorf(t *testing.T) {
type testCase struct {
threshold GOgger.Level
expectedString string
}
tt := map[string]testCase{
"debug": {
threshold: GOgger.LevelDebug,
expectedString: debugMessage +"\n" + infoMessage + "\n" + warnMessage + "\n" + errorMessage + "\n" + fatalMessage + "\n",
},
"info" : {
threshold: GOgger.LevelInfo,
expectedString: infoMessage + "\n" + warnMessage + "\n" + errorMessage + "\n" + fatalMessage + "\n",
},
"warn" : {
threshold: GOgger.LevelWarn,
expectedString: warnMessage + "\n" + errorMessage + "\n" + fatalMessage + "\n",
},
"error" : {
threshold: GOgger.LevelError,
expectedString: errorMessage + "\n" + fatalMessage + "\n",
},
"fatal" : {
threshold: GOgger.LevelFatal,
expectedString: fatalMessage +"\n",
},
}
for name ,tc := range tt {
t.Run(name, func(t *testing.T) {
tw := &testWriter{}
testedLogger := GOgger.New(tc.threshold, GOgger.WithOutput(tw))
testedLogger.Debugf(debugMessage)
testedLogger.Infof(infoMessage)
testedLogger.Warnf(warnMessage)
testedLogger.Errorf(errorMessage)
testedLogger.Fatalf(fatalMessage)
if tw.contents != tc.expectedString {
t.Errorf("invlaid contents, expected: %q, got: %q", tc.expectedString, tw.contents)
}
})
}
}