forked from PostHog/posthog-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_tracking_test.go
More file actions
118 lines (114 loc) · 2.37 KB
/
Copy patherror_tracking_test.go
File metadata and controls
118 lines (114 loc) · 2.37 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package posthog
import (
"reflect"
"testing"
"time"
)
func TestException_Validate(t *testing.T) {
now := time.Now()
tests := map[string]struct {
msg Exception
expectedError error
}{
"valid: minimal with one valid item": {
msg: Exception{
DistinctId: "user-123",
Timestamp: now,
ExceptionList: []ExceptionItem{
{Type: "title", Value: "desc"},
},
},
expectedError: nil,
},
"error: missing DistinctId": {
msg: Exception{
Timestamp: now,
ExceptionList: []ExceptionItem{
{Type: "title", Value: "desc"},
},
},
expectedError: FieldError{
Type: "posthog.Exception",
Name: "DistinctId",
Value: "",
},
},
"error: missing ExceptionList": {
msg: Exception{
DistinctId: "user-123",
Timestamp: now,
},
expectedError: FieldError{
Type: "posthog.Exception",
Name: "ExceptionList",
Value: []ExceptionItem{},
},
},
"error: item missing Type": {
msg: Exception{
DistinctId: "user-123",
Timestamp: now,
ExceptionList: []ExceptionItem{
{Type: "", Value: "Bar"},
},
},
expectedError: FieldError{
Type: "posthog.Exception",
Name: "Type",
Value: "",
},
},
"error: item missing Value": {
msg: Exception{
DistinctId: "user-123",
Timestamp: now,
ExceptionList: []ExceptionItem{
{Type: "Foo", Value: ""},
},
},
expectedError: FieldError{
Type: "posthog.Exception",
Name: "Value",
Value: "",
},
},
"valid: full nested structure": {
msg: Exception{
DistinctId: "user-123",
Timestamp: now,
ExceptionList: []ExceptionItem{
{
Type: "MyError",
Value: "something went wrong",
Mechanism: &ExceptionMechanism{
Handled: ptrBool(true),
Synthetic: ptrBool(false),
},
Stacktrace: &ExceptionStacktrace{
Type: "raw",
Frames: []StackFrame{
{
Filename: "file.go",
LineNo: 42,
Function: "package.Sample",
InApp: true,
Synthetic: false,
Platform: "go",
},
},
},
},
},
},
expectedError: nil,
},
}
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
err := tc.msg.Validate()
if !reflect.DeepEqual(err, tc.expectedError) {
t.Errorf("expected error:\n%v \ngot:\n%v", tc.expectedError, err)
}
})
}
}