forked from TV4/logrus-stackdriver-formatter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstackskip_test.go
53 lines (44 loc) · 1.12 KB
/
stackskip_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
package stackdriver
import (
"bytes"
"encoding/json"
"reflect"
"testing"
"github.com/TV4/logrus-stackdriver-formatter/test"
"github.com/kr/pretty"
"github.com/sirupsen/logrus"
)
func TestStackSkip(t *testing.T) {
var out bytes.Buffer
logger := logrus.New()
logger.Out = &out
logger.Formatter = NewFormatter(
WithService("test"),
WithVersion("0.1"),
WithStackSkip("github.com/TV4/logrus-stackdriver-formatter/test"),
)
mylog := test.LogWrapper{
Logger: logger,
}
mylog.Error("my log entry")
var got map[string]interface{}
json.Unmarshal(out.Bytes(), &got)
want := map[string]interface{}{
"severity": "ERROR",
"message": "my log entry",
"serviceContext": map[string]interface{}{
"service": "test",
"version": "0.1",
},
"context": map[string]interface{}{
"reportLocation": map[string]interface{}{
"filePath": "github.com/TV4/logrus-stackdriver-formatter/stackskip_test.go",
"lineNumber": 29.0,
"functionName": "TestStackSkip",
},
},
}
if !reflect.DeepEqual(got, want) {
t.Errorf("unexpected output = %# v; want = %# v", pretty.Formatter(got), pretty.Formatter(want))
}
}