-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging_test.go
89 lines (77 loc) · 1.46 KB
/
logging_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package cloudglog
import (
"testing"
"bytes"
"bufio"
"github.com/stretchr/testify/assert"
"strings"
)
type logCase struct {
name string
logFunc func(...interface{})
args []interface{}
expected string
}
var logCases = []logCase{
{
name: "Info",
logFunc: Info,
args: []interface{}{"Info"},
expected: " Info\n",
},
{
name: "Infoln",
logFunc: Infoln,
args: []interface{}{"Infoln"},
expected: " Infoln\n",
},
{
name: "Warning",
logFunc: Warning,
args: []interface{}{"Warning"},
expected: " Warning\n",
},
{
name: "Warningln",
logFunc: Warningln,
args: []interface{}{"Warningln"},
expected: " Warningln\n",
},
{
name: "Error",
logFunc: Error,
args: []interface{}{"Error"},
expected: " Error\n",
},
{
name: "Errorln",
logFunc: Errorln,
args: []interface{}{"Errorln"},
expected: " Errorln\n",
},
//{
// TODO: test os.Exit(1)
// name: "Fatal",
// logFunc: Fatal,
// args: []interface{}{"Fatal"},
// expected: " Fatal\n",
//},
//{
// name: "Fatalln",
// logFunc: Fatalln,
// args: []interface{}{"Fatalln"},
// expected: " Fatalln\n",
//},
}
func Test_LogFile(t *testing.T) {
var b bytes.Buffer
writer := bufio.NewWriter(&b)
LogFile(writer)
for _, testCase := range logCases {
testCase.logFunc(testCase.args...)
writer.Flush()
t.Log(string(b.Bytes()))
assert.Equal(t, testCase.expected, strings.Split(string(b.Bytes()), ":")[5], "%s wrong assertion for %s", t.Name(), testCase.name)
b.Reset()
}
}