-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger_test.go
52 lines (42 loc) · 1.02 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
package decision
import (
"bufio"
"bytes"
"testing"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)
func TestSetLogger(t *testing.T) {
newLogger := &DefaultLogger{}
SetLogger(newLogger)
assert.Equal(t, newLogger, logger)
}
func TestSetLogLevel(t *testing.T) {
l := &DefaultLogger{
Entry: logrus.New().WithField("component", "common"),
}
l.SetLevel(InfoLevel)
assert.Equal(t, logrus.InfoLevel, l.Logger.Level)
}
func TestLogf(t *testing.T) {
l := &DefaultLogger{
Entry: logrus.New().WithField("component", "common"),
}
var b bytes.Buffer
mockWriter := bufio.NewWriter(&b)
l.Logger.SetOutput(mockWriter)
l.Logf(DebugLevel, "test %v", "value")
mockWriter.Flush()
ret := b.Bytes()
assert.Equal(t, "", string(ret))
b.Reset()
l.SetLevel(DebugLevel)
l.Logf(DebugLevel, "test %v", "value")
mockWriter.Flush()
ret = b.Bytes()
assert.Contains(t, string(ret), "test value")
}
func TestNewDefaultLogger(t *testing.T) {
l := NewDefaultLogger()
assert.Equal(t, logrus.ErrorLevel, l.Logger.Level)
}