From eef9e4c3d792513b8060f2260c20d80c8229ab37 Mon Sep 17 00:00:00 2001 From: Zadat Olayinka Date: Thu, 5 Aug 2021 12:48:43 +0100 Subject: [PATCH] capture exception basic tests --- go-sdk/tracker_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/go-sdk/tracker_test.go b/go-sdk/tracker_test.go index ef8d7b3f73..990b3d300b 100644 --- a/go-sdk/tracker_test.go +++ b/go-sdk/tracker_test.go @@ -5,6 +5,8 @@ import ( "reflect" "testing" "time" + + "github.com/go-errors/errors" ) var errorTracker map[string]interface{} @@ -468,3 +470,39 @@ func TestCaptureMessageTimelineAndEventWithSameID(t *testing.T) { t.Logf("TestCaptureMessageTimelineAndEventWithSameID success expected %v, got %v", expectedMsg, actualMsg) } } +func TestCaptureExceptionReadyForServer(t *testing.T) { + timelineOpt := TrackerOption{ + MaxTimeline: 2, + } + option := FyipeTrackerOption{ + ErrorTrackerId: errorTracker["_id"].(string), + ErrorTrackerKey: errorTracker["key"].(string), + ApiUrl: apiUrl, + Options: timelineOpt, + } + + InitTracker(option) + + errorMessage := "this function is supposed to crash" + err := errors.Errorf(errorMessage) + + CaptureException(err) + + errorEvent := GetErrorEvent() + + expectedMsg := errorMessage + actualMsg := errorEvent.Exception.Message + if actualMsg != expectedMsg { + t.Errorf("TestCaptureExceptionReadyForServer failed expected %v, got %v", expectedMsg, actualMsg) + } else { + t.Logf("TestCaptureExceptionReadyForServer success expected %v, got %v", expectedMsg, actualMsg) + } + + expectedType := "exception" + actualType := errorEvent.Type + if actualType != expectedType { + t.Errorf("TestCaptureExceptionReadyForServer failed expected %v, got %v", expectedType, actualType) + } else { + t.Logf("TestCaptureExceptionReadyForServer success expected %v, got %v", expectedType, actualType) + } +}