-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger_test.go
65 lines (59 loc) · 1.96 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
package logger
import (
"bytes"
"errors"
"github.com/stretchr/testify/assert"
"testing"
)
func TestLogger_Debug(t *testing.T) {
logger := New()
logger.SetLogService("test-service")
var buf bytes.Buffer
logger.logger = logger.logger.Output(&buf)
logger.Debug("debug message", "context1")
assert.Contains(t, buf.String(), "debug message")
assert.Contains(t, buf.String(), "test-service")
assert.Contains(t, buf.String(), "context1")
}
func TestLogger_Info(t *testing.T) {
logger := New()
logger.SetLogService("test-service-info")
var buf bytes.Buffer
logger.logger = logger.logger.Output(&buf)
logger.Info("info message", "context-info")
assert.Contains(t, buf.String(), "info message")
assert.Contains(t, buf.String(), "test-service-info")
assert.Contains(t, buf.String(), "context-info")
}
func TestLogger_Warning(t *testing.T) {
logger := New()
logger.SetLogService("test-service-warning")
var buf bytes.Buffer
logger.logger = logger.logger.Output(&buf)
logger.Warning("warning message", "context-warning")
assert.Contains(t, buf.String(), "warning message")
assert.Contains(t, buf.String(), "test-service-warning")
assert.Contains(t, buf.String(), "context-warning")
}
func TestLogger_Error(t *testing.T) {
logger := New()
logger.SetLogService("test-service-error")
var buf bytes.Buffer
logger.logger = logger.logger.Output(&buf)
err := errors.New("test error log")
logger.Error(err, "context-error")
assert.Contains(t, buf.String(), err.Error())
assert.Contains(t, buf.String(), "test-service-error")
assert.Contains(t, buf.String(), "context-error")
}
func TestLogger_Critical(t *testing.T) {
logger := New()
logger.SetLogService("test-service-critical")
var buf bytes.Buffer
logger.logger = logger.logger.Output(&buf)
err := errors.New("test critical log")
logger.Error(err, "context-critical")
assert.Contains(t, buf.String(), err.Error())
assert.Contains(t, buf.String(), "test-service-critical")
assert.Contains(t, buf.String(), "context-critical")
}