forked from TV4/logrus-stackdriver-formatter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stackskip_test.go
60 lines (50 loc) · 1.15 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
54
55
56
57
58
59
60
package stackdriver
import (
"bytes"
"encoding/json"
"testing"
"github.com/TV4/logrus-stackdriver-formatter/test"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)
func TestStackSkip(t *testing.T) {
var out bytes.Buffer
skipTimestamp = true
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")
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{}{
"file": "testing/testing.go",
"line": 991.0,
"function": "tRunner",
},
},
"sourceLocation": map[string]interface{}{
"file": "testing/testing.go",
"line": 991.0,
"function": "tRunner",
},
}
got, err := json.Marshal(want)
if err != nil {
t.Error(err)
}
assert.JSONEq(t, out.String(), string(got))
skipTimestamp = false
}