-
Notifications
You must be signed in to change notification settings - Fork 159
/
log_test.go
60 lines (50 loc) · 1011 Bytes
/
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
56
57
58
59
60
package main
import (
"bufio"
"os"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
)
func TestConsole(t *testing.T) {
logger := NewLogger()
logger.SetLogger("console", nil)
logger.SetLevel(LevelInfo)
logger.Debug("debug")
logger.Info("info")
logger.Notice("notiece")
logger.Warn("warn")
logger.Error("error")
}
func TestFile(t *testing.T) {
logger := NewLogger()
logger.SetLogger("file", map[string]interface{}{"file": "test.log"})
logger.SetLevel(LevelInfo)
logger.Debug("debug")
logger.Info("info")
logger.Notice("notiece")
logger.Warn("warn")
logger.Error("error")
time.Sleep(time.Second)
f, err := os.Open("test.log")
if err != nil {
t.Fatal(err)
}
b := bufio.NewReader(f)
linenum := 0
for {
line, _, err := b.ReadLine()
if err != nil {
break
}
if len(line) > 0 {
linenum++
}
}
Convey("Test Log File Handler", t, func() {
Convey("file line nums should be 4", func() {
So(linenum, ShouldEqual, 4)
})
})
os.Remove("test.log")
}