forked from StevenACoffman/logrus-stackdriver-formatter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackskip_test.go
More file actions
65 lines (58 loc) · 1.65 KB
/
stackskip_test.go
File metadata and controls
65 lines (58 loc) · 1.65 KB
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 logadapter
import (
"bytes"
"encoding/json"
"testing"
"github.com/Mattel/logrus-stackdriver-formatter/test"
"github.com/google/go-cmp/cmp"
"github.com/sirupsen/logrus"
)
func TestStackSkip(t *testing.T) {
var out bytes.Buffer
logger := logrus.New()
logger.Out = &out
logger.Formatter = NewFormatter(
WithProjectID("test-project"),
WithService("test"),
WithVersion("0.1"),
WithStackSkip("github.com/Mattel/logrus-stackdriver-formatter"),
WithSkipTimestamp(),
)
mylog := test.LogWrapper{
Logger: logger,
}
mylog.Error("my log entry")
want := map[string]interface{}{
"@type": reportedErrorEventType,
"severity": "ERROR",
"message": "my log entry",
"logName": "projects/test-project/logs/test",
"logging.googleapis.com/trace": "projects/test-project/traces/105445aa7843bc8bf206b12000100000",
"logging.googleapis.com/spanId": "1",
"logging.googleapis.com/traceSampled": true,
"serviceContext": map[string]interface{}{
"service": "test",
"version": "0.1",
},
"context": map[string]interface{}{
"reportLocation": map[string]interface{}{
"filePath": "testing/testing.go",
"lineNumber": 1194.0,
"functionName": "tRunner",
},
},
"sourceLocation": map[string]interface{}{
"file": "testing/testing.go",
"line": 1194.0,
"function": "tRunner",
},
}
var got map[string]interface{}
err := json.Unmarshal(out.Bytes(), &got)
if err != nil {
t.Error(err)
}
if diff := cmp.Diff(want, got); diff != "" {
t.Errorf("Unexpected output (-want +got):\n%s", diff)
}
}