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
|
package log
import (
"bytes"
golog "log"
"strings"
"testing"
)
func TestDebug(t *testing.T) {
var f bytes.Buffer
golog.SetOutput(&f)
// D == false
Debug("debug")
if x := f.String(); x != "" {
t.Errorf("Expected no debug logs, got %s", x)
}
D = true
Debug("debug")
if x := f.String(); !strings.Contains(x, debug+"debug") {
t.Errorf("Expected debug log to be %s, got %s", debug+"debug", x)
}
}
func TestDebugx(t *testing.T) {
var f bytes.Buffer
golog.SetOutput(&f)
D = true
Debugf("%s", "debug")
if x := f.String(); !strings.Contains(x, debug+"debug") {
t.Errorf("Expected debug log to be %s, got %s", debug+"debug", x)
}
Debug("debug")
if x := f.String(); !strings.Contains(x, debug+"debug") {
t.Errorf("Expected debug log to be %s, got %s", debug+"debug", x)
}
}
func TestLevels(t *testing.T) {
var f bytes.Buffer
const ts = "test"
golog.SetOutput(&f)
Info(ts)
if x := f.String(); !strings.Contains(x, info+ts) {
t.Errorf("Expected log to be %s, got %s", info+ts, x)
}
Warning(ts)
if x := f.String(); !strings.Contains(x, warning+ts) {
t.Errorf("Expected log to be %s, got %s", warning+ts, x)
}
Error(ts)
if x := f.String(); !strings.Contains(x, err+ts) {
t.Errorf("Expected log to be %s, got %s", err+ts, x)
}
}
|