-
Notifications
You must be signed in to change notification settings - Fork 1
/
log_test.go
54 lines (42 loc) · 1.27 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
package log
import (
"bytes"
"testing"
"github.com/nbio/st"
log "gopkg.in/Sirupsen/logrus.v0"
)
// Since current implementation acts just as proxy to
// Logrus API, tests are not testing too much here.
func TestLogger(t *testing.T) {
var buffer bytes.Buffer
SetOutput(&buffer)
SetLevel(log.DebugLevel)
SetFormatter(&log.TextFormatter{DisableColors: true, DisableTimestamp: true, DisableSorting: true})
Info("foo bar")
st.Expect(t, safeString(buffer), `level=info msg="foo bar"`)
buffer.Reset()
Infof("foo %s", "bar")
st.Expect(t, safeString(buffer), `level=info msg="foo bar"`)
buffer.Reset()
Error("foo bar")
st.Expect(t, safeString(buffer), `level=error msg="foo bar"`)
buffer.Reset()
Errorf("foo %s", "bar")
st.Expect(t, safeString(buffer), `level=error msg="foo bar"`)
buffer.Reset()
Warn("foo bar")
st.Expect(t, safeString(buffer), `level=warning msg="foo bar"`)
buffer.Reset()
Warnf("foo %s", "bar")
st.Expect(t, safeString(buffer), `level=warning msg="foo bar"`)
buffer.Reset()
Debug("foo bar")
st.Expect(t, safeString(buffer), `level=debug msg="foo bar"`)
buffer.Reset()
Debugf("foo %s", "bar")
st.Expect(t, safeString(buffer), `level=debug msg="foo bar"`)
}
func safeString(buf bytes.Buffer) string {
b := buf.Bytes()
return string(b[:len(b)-2])
}