-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlog_test.go
55 lines (49 loc) · 1.3 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
55
package main
import (
"bytes"
"strings"
"testing"
)
func trimDatetime(s string) string {
idx := strings.Index(s, "[")
if idx == -1 {
return s
}
return s[idx:]
}
func TestDefaultLogger_Error(t *testing.T) {
buf := new(bytes.Buffer)
logger := newLogger(buf)
logger.Error("test")
want := "[error] test\n"
if got := trimDatetime(buf.String()); got != want {
t.Errorf("defaultLogger.Error(%q): got %q; want %q", "test", got, want)
}
}
func TestDefaultLogger_Errorf(t *testing.T) {
buf := new(bytes.Buffer)
logger := newLogger(buf)
logger.Errorf("%s", "test")
want := "[error] test\n"
if got := trimDatetime(buf.String()); got != want {
t.Errorf("defaultLogger.Errorf(%q, %q): got %q; want %q", "%s", "test", got, want)
}
}
func TestDefaultLogger_Notice(t *testing.T) {
buf := new(bytes.Buffer)
logger := newLogger(buf)
logger.Notice("test")
want := "[notice] test\n"
if got := trimDatetime(buf.String()); got != want {
t.Errorf("defaultLogger.Notice(%q): got %q; want %q", "test", got, want)
}
}
func TestDefaultLogger_Noticef(t *testing.T) {
buf := new(bytes.Buffer)
logger := newLogger(buf)
logger.Noticef("%s", "test")
want := "[notice] test\n"
if got := trimDatetime(buf.String()); got != want {
t.Errorf("defaultLogger.Noticef(%q, %q): got %q; want %q", "%s", "test", got, want)
}
}