capture exception basic tests

This commit is contained in:
Zadat Olayinka 2021-08-05 12:48:43 +01:00
parent 0f9d63e552
commit eef9e4c3d7

View File

@ -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)
}
}