-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_logger_test.go
110 lines (81 loc) · 2.49 KB
/
simple_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package adaptlog
import (
"testing"
)
func TestSimpleLoggerWithoutConfigurationIsNil(t *testing.T) {
if Simple != nil {
t.Fatal("Should have returned a error")
}
}
func TestNewSimpleLoggerSucceeds(t *testing.T) {
var logger = new(TestSimpleLogger)
ConfigureSimpleLogger(logger)
if Simple == nil {
t.Fatal("Logger should have been not nil!")
}
}
func TestNewSimpleLoggerLoggingSucceeds(t *testing.T) {
var logger = new(TestSimpleLogger)
ConfigureSimpleLogger(logger)
if Simple == nil {
t.Fatal("Logger should have been not nil!")
}
Simple.Print("")
Simple.Printf("Test")
Simple.Println("")
Simple.Fatal("")
Simple.Fatalf("Test")
Simple.Fatalln("")
Simple.Panic("")
Simple.Panicf("Test")
Simple.Panicln("")
if len(logger.loggingData) != 9 {
t.Fatal("Logged items should be 9!")
}
if logger.loggingData[0] != PrintMsg || logger.loggingData[1] != PrintfMsg || logger.loggingData[2] != PrintlnMsg ||
logger.loggingData[3] != FatalMsg || logger.loggingData[4] != FatalfMsg || logger.loggingData[5] != FatallnMsg ||
logger.loggingData[6] != PanicMsg || logger.loggingData[7] != PanicfMsg || logger.loggingData[8] != PaniclnMsg {
t.Fatal("Logged items do not match!")
}
}
const (
PanicMsg = "PanicMsg"
PanicfMsg = "PanicfMsg"
PaniclnMsg = "PaniclnMsg"
FatalMsg = "FatalMsg"
FatalfMsg = "FatalfMsg"
FatallnMsg = "FatallnMsg"
PrintMsg = "PrintMsg"
PrintfMsg = "PrintfMsg"
PrintlnMsg = "PrintlnMsg"
)
type TestSimpleLogger struct {
loggingData []string
}
func (l *TestSimpleLogger) Panic(args ...interface{}) {
l.loggingData = append(l.loggingData, PanicMsg)
}
func (l *TestSimpleLogger) Panicf(msg string, args ...interface{}) {
l.loggingData = append(l.loggingData, PanicfMsg)
}
func (l *TestSimpleLogger) Panicln(args ...interface{}) {
l.loggingData = append(l.loggingData, PaniclnMsg)
}
func (l *TestSimpleLogger) Fatal(args ...interface{}) {
l.loggingData = append(l.loggingData, FatalMsg)
}
func (l *TestSimpleLogger) Fatalf(msg string, args ...interface{}) {
l.loggingData = append(l.loggingData, FatalfMsg)
}
func (l *TestSimpleLogger) Fatalln(args ...interface{}) {
l.loggingData = append(l.loggingData, FatallnMsg)
}
func (l *TestSimpleLogger) Print(args ...interface{}) {
l.loggingData = append(l.loggingData, PrintMsg)
}
func (l *TestSimpleLogger) Printf(msg string, args ...interface{}) {
l.loggingData = append(l.loggingData, PrintfMsg)
}
func (l *TestSimpleLogger) Println(args ...interface{}) {
l.loggingData = append(l.loggingData, PrintlnMsg)
}