-
Notifications
You must be signed in to change notification settings - Fork 31
/
logger.format_test.go
46 lines (41 loc) · 1.15 KB
/
logger.format_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
package main
import (
"bytes"
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
func TestRawFormat(t *testing.T) {
var logs bytes.Buffer
logger := InitLogger(&LoggerConfig{
Name: "LoggerTestSuite",
Format: "raw",
Level: "trace",
})
logger.SetOutput(&logs)
logger.Debug("hi")
logger.Trace("hi")
logger.Info("hi")
logger.Warn("hi")
logger.Error("hi")
assert.Equal(t, logs.String(), "hi\nhi\nhi\nhi\nhi\n")
assert.NotContains(t, logs.String(), ColorStub)
}
func TestProductionFormat(t *testing.T) {
var logs bytes.Buffer
logger := InitLogger(&LoggerConfig{
Name: "LoggerTestSuite",
Format: "production",
Level: "trace",
})
logger.SetOutput(&logs)
logger.Debug("debug")
assert.Contains(t, logs.String(), fmt.Sprintf("%s%vm", ColorStub, Palette["gray"]))
logger.Info("info")
assert.Contains(t, logs.String(), fmt.Sprintf("%s%vm", ColorStub, Palette["green"]))
logger.Warn("warn")
assert.Contains(t, logs.String(), fmt.Sprintf("%s%vm", ColorStub, Palette["yellow"]))
logger.Error("error")
assert.Contains(t, logs.String(), fmt.Sprintf("%s%vm", ColorStub, Palette["red"]))
assert.Contains(t, logs.String(), "[LoggerTestSuite]")
}