2022-01-28 22:34:06 +00:00
|
|
|
package oneuptime
|
2021-07-28 17:27:57 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-07-29 08:00:22 +00:00
|
|
|
"reflect"
|
2021-07-28 17:27:57 +00:00
|
|
|
"testing"
|
2021-07-29 08:00:22 +00:00
|
|
|
"time"
|
2021-08-05 11:48:43 +00:00
|
|
|
|
|
|
|
"github.com/go-errors/errors"
|
2021-07-28 17:27:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var errorTracker map[string]interface{}
|
|
|
|
|
2021-07-29 08:00:22 +00:00
|
|
|
var customTimeline = &Timeline{
|
|
|
|
Category: "testing",
|
|
|
|
Data: "heyy",
|
|
|
|
Type: "info",
|
|
|
|
}
|
|
|
|
|
2021-07-28 17:27:57 +00:00
|
|
|
func init() {
|
|
|
|
fmt.Println("setting up, please wait...")
|
|
|
|
var sampleUser = GetUser()
|
|
|
|
var token, project interface{}
|
|
|
|
|
|
|
|
// Created User
|
|
|
|
res, err := MakeTestApiRequest(apiUrl+"/user/signup", sampleUser, "") // pass empty for token here
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("An error Occured %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// get token and project
|
|
|
|
token = res["tokens"].(map[string]interface{})["jwtAccessToken"]
|
|
|
|
project = res["project"]
|
|
|
|
|
|
|
|
// create a component
|
|
|
|
var sampleComponent = GetNameComponent()
|
|
|
|
createdComponent, err := MakeTestApiRequest(apiUrl+"/component/"+project.(map[string]interface{})["_id"].(string), sampleComponent, token.(string))
|
|
|
|
|
|
|
|
// create an errorTracker and set it as the global error tracker.
|
|
|
|
var sampleErrorTracker = GetNameComponent()
|
|
|
|
localErrorTracker, err := MakeTestApiRequest(apiUrl+"/error-tracker/"+project.(map[string]interface{})["_id"].(string)+"/"+createdComponent["_id"].(string)+"/create", sampleErrorTracker, token.(string))
|
|
|
|
|
|
|
|
errorTracker = localErrorTracker
|
|
|
|
fmt.Println("Test setup done, Error Tracker created, tests will begin...")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTakeInCustomTimelineEvent(t *testing.T) {
|
2021-07-29 08:00:22 +00:00
|
|
|
|
2021-07-28 17:27:57 +00:00
|
|
|
expectedResponse := customTimeline.Category
|
|
|
|
timelineOpt := TrackerOption{
|
|
|
|
MaxTimeline: 10,
|
|
|
|
}
|
2022-01-28 22:34:06 +00:00
|
|
|
option := OneUptimeTrackerOption{
|
2021-07-28 17:27:57 +00:00
|
|
|
ErrorTrackerId: errorTracker["_id"].(string),
|
|
|
|
ErrorTrackerKey: errorTracker["key"].(string),
|
|
|
|
ApiUrl: apiUrl,
|
|
|
|
Options: timelineOpt,
|
|
|
|
}
|
|
|
|
|
|
|
|
InitTracker(option)
|
|
|
|
|
|
|
|
AddToTimeline(customTimeline)
|
|
|
|
|
|
|
|
currentTimeline := GetTimeline()
|
|
|
|
|
|
|
|
actualResponse := currentTimeline[0].Category
|
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestTakeInCustomTimelineEvent", fmt.Sprint(actualResponse), expectedResponse)
|
2021-07-28 17:27:57 +00:00
|
|
|
}
|
2021-07-29 08:00:22 +00:00
|
|
|
|
|
|
|
func TestPositiveTimelineIsRequired(t *testing.T) {
|
|
|
|
expectedResponse := ErrInvalidTimeline
|
|
|
|
timelineOpt := TrackerOption{
|
|
|
|
MaxTimeline: -5,
|
|
|
|
}
|
2022-01-28 22:34:06 +00:00
|
|
|
option := OneUptimeTrackerOption{
|
2021-07-29 08:00:22 +00:00
|
|
|
ErrorTrackerId: errorTracker["_id"].(string),
|
|
|
|
ErrorTrackerKey: errorTracker["key"].(string),
|
|
|
|
ApiUrl: apiUrl,
|
|
|
|
Options: timelineOpt,
|
|
|
|
}
|
|
|
|
|
|
|
|
setupResponse := InitTracker(option)
|
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestPositiveTimelineIsRequired", fmt.Sprint(setupResponse), expectedResponse)
|
2021-08-11 17:25:25 +00:00
|
|
|
|
2021-07-29 08:00:22 +00:00
|
|
|
}
|
|
|
|
func TestCustomTimelineContainsimeStamp(t *testing.T) {
|
|
|
|
|
|
|
|
expectedResponse := reflect.TypeOf(time.Now()).String()
|
|
|
|
timelineOpt := TrackerOption{
|
|
|
|
MaxTimeline: 10,
|
|
|
|
}
|
2022-01-28 22:34:06 +00:00
|
|
|
option := OneUptimeTrackerOption{
|
2021-07-29 08:00:22 +00:00
|
|
|
ErrorTrackerId: errorTracker["_id"].(string),
|
|
|
|
ErrorTrackerKey: errorTracker["key"].(string),
|
|
|
|
ApiUrl: apiUrl,
|
|
|
|
Options: timelineOpt,
|
|
|
|
}
|
|
|
|
|
|
|
|
InitTracker(option)
|
|
|
|
|
|
|
|
AddToTimeline(customTimeline)
|
|
|
|
|
|
|
|
currentTimeline := GetTimeline()
|
|
|
|
|
|
|
|
actualResponse := reflect.TypeOf(currentTimeline[0].Timestamp).String()
|
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestCustomTimelineContainsimeStamp", fmt.Sprint(actualResponse), expectedResponse)
|
2021-07-29 08:00:22 +00:00
|
|
|
}
|
|
|
|
func TestCustomTimelineContainsEventId(t *testing.T) {
|
|
|
|
|
|
|
|
expectedResponse := reflect.TypeOf("hi").String()
|
|
|
|
timelineOpt := TrackerOption{
|
|
|
|
MaxTimeline: 10,
|
|
|
|
}
|
2022-01-28 22:34:06 +00:00
|
|
|
option := OneUptimeTrackerOption{
|
2021-07-29 08:00:22 +00:00
|
|
|
ErrorTrackerId: errorTracker["_id"].(string),
|
|
|
|
ErrorTrackerKey: errorTracker["key"].(string),
|
|
|
|
ApiUrl: apiUrl,
|
|
|
|
Options: timelineOpt,
|
|
|
|
}
|
|
|
|
|
|
|
|
InitTracker(option)
|
|
|
|
|
|
|
|
AddToTimeline(customTimeline)
|
|
|
|
|
|
|
|
currentTimeline := GetTimeline()
|
|
|
|
|
|
|
|
actualResponse := reflect.TypeOf(currentTimeline[0].EventId).String()
|
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestCustomTimelineContainsEventId", fmt.Sprint(actualResponse), expectedResponse)
|
2021-07-29 08:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTwoTimelineContainsSameEventId(t *testing.T) {
|
|
|
|
|
|
|
|
timelineOpt := TrackerOption{
|
|
|
|
MaxTimeline: 10,
|
|
|
|
}
|
2022-01-28 22:34:06 +00:00
|
|
|
option := OneUptimeTrackerOption{
|
2021-07-29 08:00:22 +00:00
|
|
|
ErrorTrackerId: errorTracker["_id"].(string),
|
|
|
|
ErrorTrackerKey: errorTracker["key"].(string),
|
|
|
|
ApiUrl: apiUrl,
|
|
|
|
Options: timelineOpt,
|
|
|
|
}
|
|
|
|
|
|
|
|
InitTracker(option)
|
|
|
|
|
|
|
|
AddToTimeline(customTimeline)
|
|
|
|
|
|
|
|
secondCustomTimeline := customTimeline
|
|
|
|
secondCustomTimeline.Category = "Randoms"
|
|
|
|
AddToTimeline(secondCustomTimeline)
|
|
|
|
|
|
|
|
currentTimeline := GetTimeline()
|
|
|
|
|
|
|
|
expectedResponse := currentTimeline[0].EventId
|
|
|
|
|
|
|
|
actualResponse := currentTimeline[1].EventId
|
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestTwoTimelineContainsSameEventId", fmt.Sprint(actualResponse), expectedResponse)
|
2021-07-29 08:00:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestOlderTimelineAreDiscarded(t *testing.T) {
|
|
|
|
timelineOpt := TrackerOption{
|
|
|
|
MaxTimeline: 2,
|
|
|
|
}
|
2022-01-28 22:34:06 +00:00
|
|
|
option := OneUptimeTrackerOption{
|
2021-07-29 08:00:22 +00:00
|
|
|
ErrorTrackerId: errorTracker["_id"].(string),
|
|
|
|
ErrorTrackerKey: errorTracker["key"].(string),
|
|
|
|
ApiUrl: apiUrl,
|
|
|
|
Options: timelineOpt,
|
|
|
|
}
|
|
|
|
|
|
|
|
InitTracker(option)
|
|
|
|
|
|
|
|
AddToTimeline(customTimeline)
|
|
|
|
|
|
|
|
secondCustomTimeline := customTimeline
|
|
|
|
secondCustomTimeline.Category = "Randoms"
|
|
|
|
AddToTimeline(secondCustomTimeline)
|
|
|
|
|
|
|
|
thirdCustomTimeline := &Timeline{
|
|
|
|
Category: "Common Grounds",
|
|
|
|
Type: "error",
|
|
|
|
}
|
|
|
|
AddToTimeline(thirdCustomTimeline)
|
|
|
|
|
|
|
|
// the second and third timeline should remain
|
|
|
|
expectedFirstTimelineResponse := secondCustomTimeline.Category // this should be the first time in the timeline stored
|
|
|
|
expectedSecondTimelineResponse := thirdCustomTimeline.Type // this should be the second time in the timeline stored
|
|
|
|
|
|
|
|
currentTimeline := GetTimeline()
|
|
|
|
|
|
|
|
actualFirstTimelineResponse := currentTimeline[0].Category
|
|
|
|
actualSecondTimelineResponse := currentTimeline[1].Type
|
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestTwoTimelineContainsSameEventId", fmt.Sprint(actualFirstTimelineResponse), expectedFirstTimelineResponse)
|
2021-07-29 08:00:22 +00:00
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestTwoTimelineContainsSameEventId", fmt.Sprint(actualSecondTimelineResponse), expectedSecondTimelineResponse)
|
2021-07-29 08:00:22 +00:00
|
|
|
|
|
|
|
}
|
2021-07-29 15:47:45 +00:00
|
|
|
func TestTagIsAdded(t *testing.T) {
|
|
|
|
timelineOpt := TrackerOption{
|
|
|
|
MaxTimeline: 2,
|
|
|
|
}
|
2022-01-28 22:34:06 +00:00
|
|
|
option := OneUptimeTrackerOption{
|
2021-07-29 15:47:45 +00:00
|
|
|
ErrorTrackerId: errorTracker["_id"].(string),
|
|
|
|
ErrorTrackerKey: errorTracker["key"].(string),
|
|
|
|
ApiUrl: apiUrl,
|
|
|
|
Options: timelineOpt,
|
|
|
|
}
|
|
|
|
|
|
|
|
InitTracker(option)
|
|
|
|
|
2021-08-11 16:47:24 +00:00
|
|
|
tagKey := "location"
|
2021-07-29 15:47:45 +00:00
|
|
|
tagValue := "Warsaw"
|
|
|
|
|
|
|
|
expectedResponse := tagKey
|
|
|
|
|
|
|
|
SetTag(tagKey, tagValue)
|
|
|
|
|
|
|
|
tags := GetTag()
|
|
|
|
|
|
|
|
actualResponse := tags[0].Key
|
2021-08-11 17:25:25 +00:00
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestTagIsAdded", fmt.Sprint(actualResponse), expectedResponse)
|
2021-08-11 17:25:25 +00:00
|
|
|
|
2021-07-29 15:47:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestTagsAreAdded(t *testing.T) {
|
|
|
|
timelineOpt := TrackerOption{
|
|
|
|
MaxTimeline: 2,
|
|
|
|
}
|
2022-01-28 22:34:06 +00:00
|
|
|
option := OneUptimeTrackerOption{
|
2021-07-29 15:47:45 +00:00
|
|
|
ErrorTrackerId: errorTracker["_id"].(string),
|
|
|
|
ErrorTrackerKey: errorTracker["key"].(string),
|
|
|
|
ApiUrl: apiUrl,
|
|
|
|
Options: timelineOpt,
|
|
|
|
}
|
|
|
|
|
|
|
|
InitTracker(option)
|
|
|
|
|
|
|
|
tags := map[string]string{
|
|
|
|
"location": "Warsaw",
|
|
|
|
"agent": "Safari",
|
|
|
|
"actor": "Tom Cruise",
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedResponse := len(tags)
|
|
|
|
|
|
|
|
SetTags(tags)
|
|
|
|
|
|
|
|
availableTags := GetTag()
|
|
|
|
|
|
|
|
actualResponse := len(availableTags)
|
|
|
|
if actualResponse != expectedResponse {
|
|
|
|
t.Errorf("TestTagsAreAdded failed expected %v, got %v", expectedResponse, actualResponse)
|
|
|
|
} else {
|
|
|
|
t.Logf("TestTagsAreAdded success expected %v, got %v", expectedResponse, actualResponse)
|
|
|
|
}
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestTagIsAdded", fmt.Sprint(actualResponse), fmt.Sprint(expectedResponse))
|
2021-08-11 17:25:25 +00:00
|
|
|
|
2021-07-29 15:47:45 +00:00
|
|
|
}
|
|
|
|
func TestOverwriteTagsWithSameKeyWhenAdded(t *testing.T) {
|
|
|
|
timelineOpt := TrackerOption{
|
|
|
|
MaxTimeline: 2,
|
|
|
|
}
|
2022-01-28 22:34:06 +00:00
|
|
|
option := OneUptimeTrackerOption{
|
2021-07-29 15:47:45 +00:00
|
|
|
ErrorTrackerId: errorTracker["_id"].(string),
|
|
|
|
ErrorTrackerKey: errorTracker["key"].(string),
|
|
|
|
ApiUrl: apiUrl,
|
|
|
|
Options: timelineOpt,
|
|
|
|
}
|
|
|
|
|
|
|
|
InitTracker(option)
|
|
|
|
|
|
|
|
tags := map[string]string{
|
|
|
|
"location": "Warsaw",
|
|
|
|
"agent": "Safari",
|
|
|
|
"actor": "Tom Cruise",
|
|
|
|
}
|
|
|
|
|
|
|
|
expectedResponse := "Kent"
|
|
|
|
|
|
|
|
SetTags(tags)
|
|
|
|
SetTag("location", "Brussels")
|
|
|
|
SetTag("location", expectedResponse)
|
|
|
|
|
|
|
|
availableTags := GetTag()
|
|
|
|
|
|
|
|
actualResponse := availableTags[0].Value // latest value for that tag location
|
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestOverwriteTagsWithSameKeyWhenAdded", fmt.Sprint(len(tags)), fmt.Sprint(len(availableTags))) // only 3 unique tags
|
2021-08-11 17:25:25 +00:00
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestOverwriteTagsWithSameKeyWhenAdded", actualResponse, expectedResponse)
|
2021-07-29 15:47:45 +00:00
|
|
|
}
|
2021-08-11 16:47:24 +00:00
|
|
|
|
2021-07-30 17:08:19 +00:00
|
|
|
func TestFingerprintShouldBeCaptureMessage(t *testing.T) {
|
|
|
|
timelineOpt := TrackerOption{
|
|
|
|
MaxTimeline: 2,
|
|
|
|
}
|
2022-01-28 22:34:06 +00:00
|
|
|
option := OneUptimeTrackerOption{
|
2021-07-30 17:08:19 +00:00
|
|
|
ErrorTrackerId: errorTracker["_id"].(string),
|
|
|
|
ErrorTrackerKey: errorTracker["key"].(string),
|
|
|
|
ApiUrl: apiUrl,
|
|
|
|
Options: timelineOpt,
|
|
|
|
}
|
|
|
|
|
|
|
|
InitTracker(option)
|
|
|
|
|
|
|
|
errorMessage := "Uncaught Exception"
|
|
|
|
|
|
|
|
expectedResponse := errorMessage
|
|
|
|
|
|
|
|
CaptureMessage(errorMessage)
|
|
|
|
|
|
|
|
errorEvent := GetErrorEvent()
|
|
|
|
|
|
|
|
actualResponse := errorEvent.Fingerprint[0]
|
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestFingerprintShouldBeCaptureMessage", actualResponse, expectedResponse)
|
2021-07-30 17:08:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestFingerprintShouldBeCustomValuesSetAheadCaptureMessage(t *testing.T) {
|
|
|
|
timelineOpt := TrackerOption{
|
|
|
|
MaxTimeline: 2,
|
|
|
|
}
|
2022-01-28 22:34:06 +00:00
|
|
|
option := OneUptimeTrackerOption{
|
2021-07-30 17:08:19 +00:00
|
|
|
ErrorTrackerId: errorTracker["_id"].(string),
|
|
|
|
ErrorTrackerKey: errorTracker["key"].(string),
|
|
|
|
ApiUrl: apiUrl,
|
|
|
|
Options: timelineOpt,
|
|
|
|
}
|
|
|
|
|
|
|
|
InitTracker(option)
|
|
|
|
|
|
|
|
errorMessage := "Uncaught Exception"
|
|
|
|
|
|
|
|
fingerprints := []string{"custom", "errors", "plankton", "ruby", "golang"}
|
|
|
|
SetFingerprint(fingerprints)
|
|
|
|
|
|
|
|
CaptureMessage(errorMessage)
|
|
|
|
|
|
|
|
errorEvent := GetErrorEvent()
|
|
|
|
|
|
|
|
for i := range errorEvent.Fingerprint {
|
|
|
|
expectedResponse := fingerprints[i]
|
|
|
|
actualResponse := errorEvent.Fingerprint[i]
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestFingerprintShouldBeCustomValuesSetAheadCaptureMessage", actualResponse, expectedResponse)
|
2021-07-30 17:08:19 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-05 09:16:50 +00:00
|
|
|
func TestCreateEventReadyForServerUsingCaptureMessage(t *testing.T) {
|
|
|
|
timelineOpt := TrackerOption{
|
|
|
|
MaxTimeline: 2,
|
|
|
|
}
|
2022-01-28 22:34:06 +00:00
|
|
|
option := OneUptimeTrackerOption{
|
2021-08-05 09:16:50 +00:00
|
|
|
ErrorTrackerId: errorTracker["_id"].(string),
|
|
|
|
ErrorTrackerKey: errorTracker["key"].(string),
|
|
|
|
ApiUrl: apiUrl,
|
|
|
|
Options: timelineOpt,
|
|
|
|
}
|
|
|
|
|
|
|
|
InitTracker(option)
|
|
|
|
|
|
|
|
errorMessage := "Uncaught Exception"
|
|
|
|
|
|
|
|
CaptureMessage(errorMessage)
|
|
|
|
|
|
|
|
errorEvent := GetErrorEvent()
|
|
|
|
|
|
|
|
expectedType := "message"
|
|
|
|
actualType := errorEvent.Type
|
2021-08-11 17:25:25 +00:00
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestFingerprintShouldBeCustomValuesSetAheadCaptureMessage", actualType, expectedType)
|
2021-08-05 09:16:50 +00:00
|
|
|
|
|
|
|
expectedMsg := errorMessage
|
|
|
|
actualMsg := errorEvent.Exception.Message
|
2021-08-11 17:25:25 +00:00
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestFingerprintShouldBeCustomValuesSetAheadCaptureMessage", actualMsg, expectedMsg)
|
2021-08-05 09:16:50 +00:00
|
|
|
}
|
|
|
|
func TestCaptureMessageTimelineAndEventWithSameID(t *testing.T) {
|
|
|
|
timelineOpt := TrackerOption{
|
|
|
|
MaxTimeline: 2,
|
|
|
|
}
|
2022-01-28 22:34:06 +00:00
|
|
|
option := OneUptimeTrackerOption{
|
2021-08-05 09:16:50 +00:00
|
|
|
ErrorTrackerId: errorTracker["_id"].(string),
|
|
|
|
ErrorTrackerKey: errorTracker["key"].(string),
|
|
|
|
ApiUrl: apiUrl,
|
|
|
|
Options: timelineOpt,
|
|
|
|
}
|
|
|
|
|
|
|
|
InitTracker(option)
|
|
|
|
|
|
|
|
AddToTimeline(customTimeline)
|
|
|
|
|
|
|
|
errorMessage := "Uncaught Exception"
|
|
|
|
|
|
|
|
CaptureMessage(errorMessage)
|
|
|
|
|
|
|
|
errorEvent := GetErrorEvent()
|
|
|
|
|
|
|
|
expectedTimelineCount := 2
|
|
|
|
actualTimelineCount := len(errorEvent.Timeline)
|
2021-08-11 17:25:25 +00:00
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestCaptureMessageTimelineAndEventWithSameID", fmt.Sprint(actualTimelineCount), fmt.Sprint(expectedTimelineCount))
|
2021-08-05 09:16:50 +00:00
|
|
|
|
|
|
|
expectedEventId := errorEvent.EventId
|
|
|
|
actualEventId := errorEvent.Timeline[0].EventId
|
2021-08-11 17:25:25 +00:00
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestCaptureMessageTimelineAndEventWithSameID", actualEventId, expectedEventId)
|
2021-08-05 09:16:50 +00:00
|
|
|
|
|
|
|
expectedMsg := errorMessage
|
|
|
|
actualMsg := errorEvent.Exception.Message
|
2021-08-11 17:25:25 +00:00
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestCaptureMessageTimelineAndEventWithSameID", actualMsg, expectedMsg)
|
2021-08-11 17:25:25 +00:00
|
|
|
|
2021-08-05 09:16:50 +00:00
|
|
|
}
|
2021-08-05 11:48:43 +00:00
|
|
|
func TestCaptureExceptionReadyForServer(t *testing.T) {
|
|
|
|
timelineOpt := TrackerOption{
|
|
|
|
MaxTimeline: 2,
|
|
|
|
}
|
2022-01-28 22:34:06 +00:00
|
|
|
option := OneUptimeTrackerOption{
|
2021-08-05 11:48:43 +00:00
|
|
|
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
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestCaptureExceptionReadyForServer", actualMsg, expectedMsg)
|
2021-08-05 11:48:43 +00:00
|
|
|
|
|
|
|
expectedType := "exception"
|
|
|
|
actualType := errorEvent.Type
|
2021-08-11 17:25:25 +00:00
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestCaptureExceptionReadyForServer", actualType, expectedType)
|
2021-08-11 17:25:25 +00:00
|
|
|
|
2021-08-05 11:48:43 +00:00
|
|
|
}
|
2021-08-10 17:50:28 +00:00
|
|
|
func TestCaptureExceptionAndCaptureMessageWithDifferentID(t *testing.T) {
|
2021-08-05 23:06:25 +00:00
|
|
|
timelineOpt := TrackerOption{
|
|
|
|
MaxTimeline: 2,
|
|
|
|
}
|
2022-01-28 22:34:06 +00:00
|
|
|
option := OneUptimeTrackerOption{
|
2021-08-05 23:06:25 +00:00
|
|
|
ErrorTrackerId: errorTracker["_id"].(string),
|
|
|
|
ErrorTrackerKey: errorTracker["key"].(string),
|
|
|
|
ApiUrl: apiUrl,
|
|
|
|
Options: timelineOpt,
|
|
|
|
}
|
|
|
|
|
|
|
|
InitTracker(option)
|
|
|
|
|
2021-08-10 17:50:28 +00:00
|
|
|
AddToTimeline(customTimeline)
|
|
|
|
|
2021-08-05 23:06:25 +00:00
|
|
|
errorMessage := "this function is supposed to crash"
|
2021-08-10 17:50:28 +00:00
|
|
|
|
|
|
|
event := CaptureMessage(errorMessage)
|
|
|
|
|
|
|
|
AddToTimeline(customTimeline)
|
|
|
|
|
2021-08-05 23:06:25 +00:00
|
|
|
err := errors.Errorf(errorMessage)
|
|
|
|
|
2021-08-10 17:50:28 +00:00
|
|
|
newEvent := CaptureException(err)
|
2021-08-05 23:06:25 +00:00
|
|
|
|
2021-08-10 17:50:28 +00:00
|
|
|
// ensure that the first event have a type message, same error message
|
|
|
|
expectedType := "message"
|
|
|
|
actualType := event.Type
|
2021-08-11 17:25:25 +00:00
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestCaptureExceptionAndCaptureMessageWithDifferentID", actualType, expectedType)
|
2021-08-05 23:06:25 +00:00
|
|
|
|
2021-08-10 17:50:28 +00:00
|
|
|
actualMessage := event.Content.(map[string]interface{})["message"].(string)
|
2021-08-11 17:25:25 +00:00
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestCaptureExceptionAndCaptureMessageWithDifferentID", actualMessage, errorMessage)
|
2021-08-05 23:06:25 +00:00
|
|
|
|
2021-08-10 17:50:28 +00:00
|
|
|
// ensure that the second event have a type exception, same error message
|
|
|
|
expectedType = "exception"
|
|
|
|
actualType = newEvent.Type
|
2021-08-11 17:25:25 +00:00
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestCaptureExceptionAndCaptureMessageWithDifferentID", actualType, expectedType)
|
2021-08-05 23:06:25 +00:00
|
|
|
|
2021-08-10 17:50:28 +00:00
|
|
|
actualMessage = newEvent.Content.(map[string]interface{})["message"].(string)
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestCaptureExceptionAndCaptureMessageWithDifferentID", actualMessage, errorMessage)
|
2021-08-10 17:50:28 +00:00
|
|
|
|
|
|
|
// confim their eventId is different
|
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertNotEqual(t, "TestCaptureExceptionAndCaptureMessageWithDifferentID", event.ID, newEvent.ID)
|
2021-08-10 17:50:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCapturedErrorWithDifferentProperties(t *testing.T) {
|
|
|
|
timelineOpt := TrackerOption{
|
2021-08-10 18:27:44 +00:00
|
|
|
MaxTimeline: 2,
|
|
|
|
CaptureCodeSnippet: true,
|
2021-08-10 17:50:28 +00:00
|
|
|
}
|
2022-01-28 22:34:06 +00:00
|
|
|
option := OneUptimeTrackerOption{
|
2021-08-10 17:50:28 +00:00
|
|
|
ErrorTrackerId: errorTracker["_id"].(string),
|
|
|
|
ErrorTrackerKey: errorTracker["key"].(string),
|
|
|
|
ApiUrl: apiUrl,
|
|
|
|
Options: timelineOpt,
|
|
|
|
}
|
|
|
|
|
|
|
|
InitTracker(option)
|
|
|
|
|
|
|
|
// add timeline to first tracker
|
|
|
|
AddToTimeline(customTimeline)
|
|
|
|
|
|
|
|
errorMessage := "this function is supposed to crash"
|
|
|
|
|
|
|
|
event := CaptureMessage(errorMessage)
|
|
|
|
|
|
|
|
// add timeline and tag to second tracker
|
|
|
|
AddToTimeline(customTimeline)
|
|
|
|
|
|
|
|
tagKey := "Location"
|
|
|
|
tagValue := "Warsaw"
|
|
|
|
|
|
|
|
SetTag(tagKey, tagValue)
|
|
|
|
|
|
|
|
err := errors.Errorf(errorMessage)
|
|
|
|
|
|
|
|
newEvent := CaptureException(err)
|
|
|
|
|
|
|
|
// ensure that the first event have a type message, same error message and two timeline (one custom, one generic)
|
|
|
|
expectedType := "message"
|
|
|
|
actualType := event.Type
|
2021-08-11 17:25:25 +00:00
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestCapturedErrorWithDifferentProperties", actualType, expectedType)
|
2021-08-10 17:50:28 +00:00
|
|
|
|
|
|
|
actualMessage := event.Content.(map[string]interface{})["message"].(string)
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestCapturedErrorWithDifferentProperties", actualMessage, errorMessage)
|
2021-08-10 17:50:28 +00:00
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestCapturedErrorWithDifferentProperties", fmt.Sprint(len(event.Timeline)), "2")
|
2021-08-10 17:50:28 +00:00
|
|
|
|
|
|
|
// ensure that the second event have a type exception, same error message and 2 tags
|
|
|
|
expectedType = "exception"
|
|
|
|
actualType = newEvent.Type
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestCapturedErrorWithDifferentProperties", actualType, expectedType)
|
2021-08-10 17:50:28 +00:00
|
|
|
|
|
|
|
actualMessage = newEvent.Content.(map[string]interface{})["message"].(string)
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestCapturedErrorWithDifferentProperties", actualMessage, errorMessage)
|
2021-08-10 17:50:28 +00:00
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestCapturedErrorWithDifferentProperties", fmt.Sprint(len(newEvent.Timeline)), "2")
|
2021-08-11 17:25:25 +00:00
|
|
|
|
2021-08-12 09:55:10 +00:00
|
|
|
AssertEqual(t, "TestCapturedErrorWithDifferentProperties", fmt.Sprint(len(newEvent.Tags)), "2") // the default and custom tag
|
2021-08-10 17:50:28 +00:00
|
|
|
|
2021-08-05 23:06:25 +00:00
|
|
|
}
|