forked from openware/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger_test.go
87 lines (78 loc) · 1.82 KB
/
logger_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
package logger
import (
"os"
"path/filepath"
"testing"
)
var (
trueptr = func(b bool) *bool { return &b }(true)
falseptr = func(b bool) *bool { return &b }(false)
)
func TestCloseLogFile(t *testing.T) {
Logger = &Logging{
Enabled: trueptr,
Level: "DEBUG",
ColourOutput: false,
File: "",
Rotate: false,
}
SetupLogger()
err := CloseLogFile()
if err != nil {
t.Fatalf("CloseLogFile failed with %v", err)
}
os.Remove(filepath.Join(LogPath, Logger.File))
}
func TestSetupOutputsValidPath(t *testing.T) {
Logger.Enabled = trueptr
Logger.File = "debug.txt"
LogPath = "../testdata/"
err := setupOutputs()
if err != nil {
t.Fatalf("SetupOutputs failed expected nil got %v", err)
}
err = CloseLogFile()
if err != nil {
t.Fatalf("CloseLogFile failed with %v", err)
}
err = os.Remove(filepath.Join(LogPath, Logger.File))
if err != nil {
t.Fatal("Test Failed - SetupOutputsValidPath() error could not remove test file", err)
}
}
func TestSetupOutputsInValidPath(t *testing.T) {
Logger.Enabled = trueptr
Logger.File = "debug.txt"
LogPath = "../testdataa/"
err := setupOutputs()
if err != nil {
if !os.IsNotExist(err) {
t.Fatalf("SetupOutputs failed expected %v got %v", os.ErrNotExist, err)
}
}
err = os.Remove(filepath.Join(LogPath, Logger.File))
if err == nil {
t.Fatal("Test Failed - SetupOutputsInValidPath() error cannot be nil")
}
}
func BenchmarkDebugf(b *testing.B) {
Logger = &Logging{
Enabled: trueptr,
Level: "DEBUG",
ColourOutput: false,
File: "",
Rotate: false,
}
SetupLogger()
b.ResetTimer()
for n := 0; n < b.N; n++ {
Debugf("This is a debug benchmark %d", n)
}
}
func BenchmarkDebugfLoggerDisabled(b *testing.B) {
clearAllLoggers()
b.ResetTimer()
for n := 0; n < b.N; n++ {
Debugf("this is a debug benchmark")
}
}