-
Notifications
You must be signed in to change notification settings - Fork 4
/
decorator_test.go
52 lines (42 loc) · 1.06 KB
/
decorator_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
package golog_test
import (
"context"
"strings"
"testing"
. "github.com/damianopetrungaro/golog"
)
func TestStackTraceDecorator_Decorate(t *testing.T) {
const fieldName = "stacktrace"
w := &FakeWriter{}
logger := New(w).WithDecorator(NewStackTraceDecorator(fieldName, 2))
wantStack := []string{
"golog/decorator_test.go:000",
"testing/testing.go:111",
}
ctx := context.Background()
logger.With(String("hello", "world")).Info(ctx, "An info message")
for _, f := range w.Entry.Fields() {
if f.Key() != fieldName {
continue
}
stack, ok := f.Value().([]string)
if !ok {
break
}
for i, trace := range stack {
if strings.Contains(trace, "golog/decorator_test.go") {
stack[i] = "golog/decorator_test.go:000"
}
if strings.Contains(trace, "testing/testing.go") {
stack[i] = "testing/testing.go:111"
}
}
if strings.Join(stack, "##") != strings.Join(wantStack, "##") {
t.Error("could not match trace")
t.Errorf("got: %v", stack)
t.Errorf("want: %v", wantStack)
}
return
}
t.Error("could not find stacktrace field")
}