-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogger_test.go
45 lines (38 loc) · 943 Bytes
/
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
package golog_test
import (
"fmt"
"github.com/chapsuk/golog"
test "github.com/smartystreets/goconvey/convey"
"os"
"testing"
)
type ErrorWriter struct{}
func (w *ErrorWriter) Write(p []byte) (int, error) {
return 0, fmt.Errorf("%s", "error")
}
func TestLogger(t *testing.T) {
test.Convey("Save context after WithContext called", t, func() {
log1 := golog.NewLogger(os.Stderr, &golog.JSONFormatter{}, golog.Context{
"field": "main",
"name": "log1",
})
log2 := log1.WithContext(golog.Context{
"name": "log2",
"src": "foo",
})
test.So(golog.Context{
"field": "main",
"name": "log1",
}, test.ShouldResemble, log1.GetContext())
test.So(golog.Context{
"field": "main",
"name": "log2",
"src": "foo",
}, test.ShouldResemble, log2.GetContext())
})
test.Convey("ErrorWriter. Writer return error: \n", t, func() {
log := golog.New()
log.SetOutput(&ErrorWriter{})
log.Print(foo)
})
}