@@ -145,8 +145,6 @@ func TestNotify(t *testing.T) {
145145func TestNotifyWithCustomMessage (t * testing.T ) {
146146 ts , reports := setup ()
147147 defer ts .Close ()
148- sessionTracker = nil
149- startSessionTracking ()
150148
151149 ctx , cancel := setupState ()
152150 defer cancel ()
@@ -165,7 +163,6 @@ func TestNotifyWithCustomMessage(t *testing.T) {
165163 App : & appJSON {ReleaseStage : "test" , Type : "foo" , Version : "1.2.3" },
166164 Context : "" ,
167165 Device : & deviceJSON {Hostname : "web1" },
168- Session : & sessionJSON {Events : sessions.EventCounts {Handled : 0 , Unhandled : 1 }},
169166 Severity : "warning" ,
170167 SeverityReason : & severityReasonJSON {Type : SeverityReasonHandledError },
171168 Unhandled : false ,
@@ -175,6 +172,103 @@ func TestNotifyWithCustomMessage(t *testing.T) {
175172 })
176173}
177174
175+ func TestNotifyWithMultipleErrorClassAndMessage (t * testing.T ) {
176+ ts , reports := setup ()
177+ defer ts .Close ()
178+
179+ ctx , cancel := setupState ()
180+ defer cancel ()
181+ config := generateSampleConfig (ts .URL , ctx )
182+
183+ // Test with multiple ErrorClass and Message - last one should win
184+ Notify (
185+ fmt .Errorf ("original error" ),
186+ config ,
187+ ErrorClass {Name : "FirstErrorClass" },
188+ Message {String : "First message" },
189+ ErrorClass {Name : "SecondErrorClass" },
190+ Message {String : "Second message" },
191+ )
192+
193+ json , err := simplejson .NewJson (<- reports )
194+
195+ if err != nil {
196+ t .Fatal (err )
197+ }
198+
199+ assertPayload (t , json , eventJSON {
200+ App : & appJSON {ReleaseStage : "test" , Type : "foo" , Version : "1.2.3" },
201+ Context : "" ,
202+ Device : & deviceJSON {Hostname : "web1" },
203+ Severity : "warning" ,
204+ SeverityReason : & severityReasonJSON {Type : SeverityReasonHandledError },
205+ Unhandled : false ,
206+ Request : & RequestJSON {},
207+ User : & User {},
208+ Exceptions : []exceptionJSON {{ErrorClass : "SecondErrorClass" , Message : "Second message" }},
209+ })
210+ }
211+
212+ func TestNotifyWithOnlyErrorClass (t * testing.T ) {
213+ ts , reports := setup ()
214+ defer ts .Close ()
215+
216+ ctx , cancel := setupState ()
217+ defer cancel ()
218+ config := generateSampleConfig (ts .URL , ctx )
219+
220+ // Test with only custom ErrorClass (message from error)
221+ Notify (fmt .Errorf ("error message from error" ), config , ErrorClass {Name : "CustomErrorClass" })
222+
223+ json , err := simplejson .NewJson (<- reports )
224+
225+ if err != nil {
226+ t .Fatal (err )
227+ }
228+
229+ assertPayload (t , json , eventJSON {
230+ App : & appJSON {ReleaseStage : "test" , Type : "foo" , Version : "1.2.3" },
231+ Context : "" ,
232+ Device : & deviceJSON {Hostname : "web1" },
233+ Severity : "warning" ,
234+ SeverityReason : & severityReasonJSON {Type : SeverityReasonHandledError },
235+ Unhandled : false ,
236+ Request : & RequestJSON {},
237+ User : & User {},
238+ Exceptions : []exceptionJSON {{ErrorClass : "CustomErrorClass" , Message : "error message from error" }},
239+ })
240+ }
241+
242+ func TestNotifyWithOnlyMessage (t * testing.T ) {
243+ ts , reports := setup ()
244+ defer ts .Close ()
245+
246+ ctx , cancel := setupState ()
247+ defer cancel ()
248+ config := generateSampleConfig (ts .URL , ctx )
249+
250+ // Test with only custom Message (error class from error type)
251+ Notify (fmt .Errorf ("original error" ), config , Message {String : "custom message only" })
252+
253+ json , err := simplejson .NewJson (<- reports )
254+
255+ if err != nil {
256+ t .Fatal (err )
257+ }
258+
259+ assertPayload (t , json , eventJSON {
260+ App : & appJSON {ReleaseStage : "test" , Type : "foo" , Version : "1.2.3" },
261+ Context : "" ,
262+ Device : & deviceJSON {Hostname : "web1" },
263+ Severity : "warning" ,
264+ SeverityReason : & severityReasonJSON {Type : SeverityReasonHandledError },
265+ Unhandled : false ,
266+ Request : & RequestJSON {},
267+ User : & User {},
268+ Exceptions : []exceptionJSON {{ErrorClass : "*errors.errorString" , Message : "custom message only" }},
269+ })
270+ }
271+
178272type testPublisher struct {
179273 sync bool
180274}
0 commit comments