@@ -116,6 +116,48 @@ func TestBacktraceEntry_UnmarshalJSON(t *testing.T) {
116
116
},
117
117
wantErr : false ,
118
118
},
119
+ {
120
+ name : "backtrace entry with all optional fields" ,
121
+ input : `{
122
+ "number": "25",
123
+ "column": 15,
124
+ "file": "/app/models/user.rb",
125
+ "method": "authenticate",
126
+ "class": "User",
127
+ "type": "instance",
128
+ "args": ["email@example.com", "password"],
129
+ "source": {"25": "user = User.find_by(email: email)"},
130
+ "context": "app"
131
+ }` ,
132
+ want : BacktraceEntry {
133
+ Number : "25" ,
134
+ Column : func () * StringOrInt { s := StringOrInt ("15" ); return & s }(),
135
+ File : "/app/models/user.rb" ,
136
+ Method : "authenticate" ,
137
+ Class : "User" ,
138
+ Type : "instance" ,
139
+ Args : []interface {}{"email@example.com" , "password" },
140
+ Source : map [string ]interface {}{"25" : "user = User.find_by(email: email)" },
141
+ Context : "app" ,
142
+ },
143
+ wantErr : false ,
144
+ },
145
+ {
146
+ name : "backtrace entry with column as string" ,
147
+ input : `{
148
+ "number": 42,
149
+ "column": "8",
150
+ "file": "/lib/helper.js",
151
+ "method": "processData"
152
+ }` ,
153
+ want : BacktraceEntry {
154
+ Number : "42" ,
155
+ Column : func () * StringOrInt { s := StringOrInt ("8" ); return & s }(),
156
+ File : "/lib/helper.js" ,
157
+ Method : "processData" ,
158
+ },
159
+ wantErr : false ,
160
+ },
119
161
}
120
162
121
163
for _ , tt := range tests {
@@ -139,6 +181,26 @@ func TestBacktraceEntry_UnmarshalJSON(t *testing.T) {
139
181
if entry .Context != tt .want .Context {
140
182
t .Errorf ("BacktraceEntry.Context = %v, want %v" , entry .Context , tt .want .Context )
141
183
}
184
+ // Check Column
185
+ if tt .want .Column != nil && entry .Column != nil {
186
+ if string (* entry .Column ) != string (* tt .want .Column ) {
187
+ t .Errorf ("BacktraceEntry.Column = %v, want %v" , * entry .Column , * tt .want .Column )
188
+ }
189
+ } else if (tt .want .Column == nil ) != (entry .Column == nil ) {
190
+ t .Errorf ("BacktraceEntry.Column = %v, want %v" , entry .Column , tt .want .Column )
191
+ }
192
+ // Check Class
193
+ if entry .Class != tt .want .Class {
194
+ t .Errorf ("BacktraceEntry.Class = %v, want %v" , entry .Class , tt .want .Class )
195
+ }
196
+ // Check Type
197
+ if entry .Type != tt .want .Type {
198
+ t .Errorf ("BacktraceEntry.Type = %v, want %v" , entry .Type , tt .want .Type )
199
+ }
200
+ // Check Args length
201
+ if len (entry .Args ) != len (tt .want .Args ) {
202
+ t .Errorf ("BacktraceEntry.Args length = %v, want %v" , len (entry .Args ), len (tt .want .Args ))
203
+ }
142
204
}
143
205
})
144
206
}
0 commit comments