-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlog_test.go
135 lines (121 loc) · 3.02 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
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package log
import (
"strconv"
"sync"
"testing"
)
// Test CreateClient() and Client.Destroy()
func TestCreateDestroy(t *testing.T) {
// Ensure only stderr exists at the beginning
if len(clients) != 1 {
t.Errorf("Expected 1 client, but found %d", len(clients))
}
// Create a new client, ensure it's added
c := CreateClient()
if len(clients) != 2 {
t.Errorf("Expected 2 clients, but found %d", len(clients))
}
// Destroy it and ensure it's actually removed from the array
c.Destroy()
if len(clients) != 1 {
t.Errorf("Expected 1 client, but found %d", len(clients))
}
}
// SetLogLevel set log level of logger
func TestSetLogLevel(t *testing.T) {
logLevels := [...]Level{LTrace, LDebug, LInfo, LWarn, LError, LPanic, LFatal}
c := CreateClient()
for _, x := range logLevels {
c.SetLogLevel(x)
if c.GetLogLevel() != x {
t.Errorf("Got logLevel %d, but expected %d", int(c.GetLogLevel()), int(x))
}
}
c.Destroy()
}
func BenchmarkDebugSerial(b *testing.B) {
c := CreateClient()
var x sync.WaitGroup
x.Add(b.N)
for i := 0; i < b.N; i++ {
Debug(i)
go func() {
c.Get()
x.Done()
}()
}
x.Wait()
c.Destroy()
}
// Trace ensure logs come out in the right order
func TestOrder(t *testing.T) {
testString := "Testing trace: "
c := CreateClient()
c.SetLogLevel(LTrace)
for i := 0; i < 5000; i++ {
Trace(testString + strconv.Itoa(i))
if testString+strconv.Itoa(i) != c.Get().Output {
t.Error("Trace input doesn't match output")
}
}
}
// Debug prints out logs on debug level
func TestDebug(t *testing.T) {
Debug("Test of Debug")
// if logLevel >= LDebug {
// entry := logger.WithFields(logrus.Fields{})
// entry.Data["file"] = fileInfo(2)
// entry.Debug(args...)
// }
}
// Info prints out logs on info level
func TestInfo(t *testing.T) {
// if logLevel >= LInfo {
// entry := logger.WithFields(logrus.Fields{})
// entry.Data["file"] = fileInfo(2)
// entry.Info(args...)
// }
}
// Print prints out logs on info level
func TestPrint(t *testing.T) {
// if logLevel >= LInfo {
// entry := logger.WithFields(logrus.Fields{})
// entry.Data["file"] = fileInfo(2)
// entry.Info(args...)
// }
}
// Warn prints out logs on warn level
func TestWarn(t *testing.T) {
// if logLevel >= LWarn {
// entry := logger.WithFields(logrus.Fields{})
// entry.Data["file"] = fileInfo(2)
// entry.Warn(args...)
// }
}
// Error prints out logs on error level
func TestError(t *testing.T) {
// if logLevel >= LError {
// entry := logger.WithFields(logrus.Fields{})
// entry.Data["file"] = fileInfo(2)
// entry.Error(args...)
// }
}
// Fatal prints out logs on fatal level
func TestFatal(t *testing.T) {
// if logLevel >= LFatal {
// entry := logger.WithFields(logrus.Fields{})
// entry.Data["file"] = fileInfo(2)
// entry.Fatal(args...)
// }
}
// Panic prints out logs on panic level
func TestPanic(t *testing.T) {
// if logLevel >= LPanic {
// entry := logger.WithFields(logrus.Fields{})
// entry.Data["file"] = fileInfo(2)
// entry.Panic(args...)
// }
}
func TestFlush(t *testing.T) {
defer Flush()
}