-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclog_test.go
71 lines (61 loc) · 1.37 KB
/
clog_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
package clog
import (
"bytes"
"os"
"reflect"
"testing"
)
func expect(t *testing.T, a interface{}, b interface{}) {
if a != b {
t.Errorf("Expected %v (type %v) - Got %v (type %v)", b, reflect.TypeOf(b), a, reflect.TypeOf(a))
} else {
t.Log("Test ok!")
}
}
func TestLog(t *testing.T) {
SetLogLevel(LOG_LEVEL_DEBUG)
logstr := "hello world!!"
logstr2 := "goodbye world."
Infof("%s, %s", logstr, logstr2)
Debugf("%s, %s", logstr, logstr2)
Errorf("%s, %s", logstr, logstr2)
Warnf("%s, %s", logstr, logstr2)
Tracef("%s, %s", logstr, logstr2)
Printf("%s, %s", logstr, logstr2)
Info(logstr, logstr2)
Debug(logstr, logstr2)
Error(logstr, logstr2)
Warn(logstr, logstr2)
Trace(logstr, logstr2)
Println(logstr, logstr2)
Print(logstr, logstr2)
expect(t, GetLogLevelText(), "debug")
t.Log("TEST OK")
}
func TestLogLevel(t *testing.T) {
SetLogLevel(LOG_LEVEL_TRACE)
lvl := GetLogLevel()
expect(t, lvl, LOG_LEVEL_TRACE)
}
func TestLogFile(t *testing.T) {
SetLogFile("/tmp/asdsaaf")
CloseLogFile()
var null *os.File = nil
expect(t, logfileFd, null)
}
func TestLogger(t *testing.T) {
var buf bytes.Buffer
s := "hello world!"
SetOutput(&buf)
Info(s)
t.Log("buffer:", &buf)
buf.Reset()
Warn(s)
t.Log("buffer:", &buf)
}
func TestLogLevelEnv(t *testing.T) {
os.Setenv("CLOG_LOGLEVEL", "fatal")
checkLogEnv()
lvl := GetLogLevel()
expect(t, lvl, LOG_LEVEL_FATAL)
}