-
Notifications
You must be signed in to change notification settings - Fork 2
/
logger_test.go
55 lines (49 loc) · 1.39 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
package featurevisor
import (
"bytes"
"fmt"
"strings"
"testing"
)
func TestLogger(t *testing.T) {
var buf bytes.Buffer
logger := CreateLogger(CreateLoggerOptions{
Levels: []LogLevel{Debug, Info, Warn, Error},
Handler: func(level LogLevel, message LogMessage, details LogDetails) {
buf.WriteString(string(level))
buf.WriteString(" ")
buf.WriteString(string(message))
buf.WriteString(" ")
buf.WriteString(fmt.Sprintf("%v", details))
buf.WriteString("\n")
},
})
t.Run("Test debug log", func(t *testing.T) {
buf.Reset()
logger.Debug("Debug message", LogDetails{"key": "value"})
if !strings.Contains(buf.String(), "Debug message") {
t.Errorf("Debug log did not work as expected")
}
})
t.Run("Test info log", func(t *testing.T) {
buf.Reset()
logger.Info("Info message", LogDetails{"key": "value"})
if !strings.Contains(buf.String(), "Info message") {
t.Errorf("Info log did not work as expected")
}
})
t.Run("Test warn log", func(t *testing.T) {
buf.Reset()
logger.Warn("Warn message", LogDetails{"key": "value"})
if !strings.Contains(buf.String(), "Warn message") {
t.Errorf("Warn log did not work as expected")
}
})
t.Run("Test error log", func(t *testing.T) {
buf.Reset()
logger.Error("Error message", LogDetails{"key": "value"})
if !strings.Contains(buf.String(), "Error message") {
t.Errorf("Error log did not work as expected")
}
})
}