-
Notifications
You must be signed in to change notification settings - Fork 48
/
logger_test.go
60 lines (54 loc) · 1.22 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
package proxmox
import (
"bytes"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLeveledLogger(t *testing.T) {
tests := []struct {
level int
input string
stdout string
stderr string
}{
{
level: LevelError,
input: "log",
stderr: "[ERROR] error log\n",
stdout: "",
},
{
level: LevelWarn,
input: "log",
stderr: "[ERROR] error log\n[WARN] warn log\n",
stdout: "",
},
{
level: LevelInfo,
input: "log",
stderr: "[ERROR] error log\n[WARN] warn log\n",
stdout: "[INFO] info log\n",
},
{
level: LevelDebug,
input: "log",
stderr: "[ERROR] error log\n[WARN] warn log\n",
stdout: "[INFO] info log\n[DEBUG] debug log\n",
},
}
for _, test := range tests {
err := &bytes.Buffer{}
out := &bytes.Buffer{}
log := &LeveledLogger{Level: test.level, stderrOverride: err, stdoutOverride: out}
log.Errorf("error %s", test.input)
log.Warnf("warn %s", test.input)
log.Infof("info %s", test.input)
log.Debugf("debug %s", test.input)
assert.Equal(t, test.stdout, out.String())
assert.Equal(t, test.stderr, err.String())
}
log := &LeveledLogger{Level: LevelDebug}
assert.Equal(t, os.Stderr, log.stderr())
assert.Equal(t, os.Stdout, log.stdout())
}