From 518cc1948517d2a13aaeea0eafcccbad5a12f270 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Wed, 3 Jun 2020 09:51:03 -0400 Subject: [PATCH] fix: PR review - fix: Change how DSN API URL is formatted - test: Don't calculate DSN every loop in transport test - test: Compare envelope payload using cpm.Diff --- dsn.go | 2 +- interfaces.go | 3 ++- transport_test.go | 27 ++++++++++++++++++--------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/dsn.go b/dsn.go index 7487ce22e..68392deef 100644 --- a/dsn.go +++ b/dsn.go @@ -151,7 +151,7 @@ func getAPIURL(dsn Dsn, s string) *url.URL { if dsn.path != "" { rawURL += dsn.path } - rawURL += fmt.Sprintf("/api/%d/%v/", dsn.projectID, s) + rawURL += fmt.Sprintf("/api/%d/%s/", dsn.projectID, s) parsedURL, _ := url.Parse(rawURL) return parsedURL } diff --git a/interfaces.go b/interfaces.go index 4ecfd2fdc..dd304c0ef 100644 --- a/interfaces.go +++ b/interfaces.go @@ -147,6 +147,7 @@ type Exception struct { type EventID string // TraceContext describes the context of the trace. +// // Experimental: This is part of a beta feature of the SDK. type TraceContext struct { TraceID string `json:"trace_id"` @@ -169,7 +170,7 @@ type Span struct { Status string `json:"status"` } -// Event is the fundamental data structure that is sent to Sentry +// Event is the fundamental data structure that is sent to Sentry. type Event struct { Type string `json:"type,omitempty"` Breadcrumbs []*Breadcrumb `json:"breadcrumbs,omitempty"` diff --git a/transport_test.go b/transport_test.go index 891ede74e..8a0a1c781 100644 --- a/transport_test.go +++ b/transport_test.go @@ -10,6 +10,8 @@ import ( "sync/atomic" "testing" "time" + + "github.com/google/go-cmp/cmp" ) type unserializableType struct { @@ -21,6 +23,9 @@ const enhancedEvent = "{\"extra\":{\"info\":\"Original event couldn't be marshal "the data that uses interface{} type. Please verify that the data you attach to the scope is serializable.\"}," + "\"message\":\"mkey\",\"sdk\":{},\"user\":{}}" +const envPayload = `{"type":"transaction"}` + + `{"type":"transaction","sdk":{},"timestamp":"1970-01-01T00:00:05Z","user":{},"start_timestamp":"1970-01-01T00:00:03Z"}` + func TestGetRequestBodyFromEventValid(t *testing.T) { body := getRequestBodyFromEvent(&Event{ Message: "mkey", @@ -128,7 +133,10 @@ func TestGetRequestBodyFromEventCompletelyInvalid(t *testing.T) { func TestGetEnvelopeFromBody(t *testing.T) { body := getRequestBodyFromEvent(&Event{ - Message: "testing", + Type: transactionType, + Spans: []*Span{}, + StartTimestamp: time.Unix(3, 0).UTC(), + Timestamp: time.Unix(5, 0).UTC(), }) env := getEnvelopeFromBody(body) envString := env.String() @@ -152,9 +160,10 @@ func TestGetEnvelopeFromBody(t *testing.T) { t.Error("sent_at was not set in header") } - payload := envParts[2] - if payload == "" { - t.Error("Item payload is empty") + want := envParts[1] + envParts[2] + got := envPayload + if diff := cmp.Diff(want, got); diff != "" { + t.Errorf("Event mismatch (-want +got):\n%s", diff) } } @@ -185,12 +194,12 @@ func TestGetRequestFromEvent(t *testing.T) { for _, test := range testCases { test := test - t.Run(test.testName, func(t *testing.T) { - dsn, err := NewDsn("https://key@host/path/42") - if err != nil { - t.Fatal(err) - } + dsn, err := NewDsn("https://key@host/path/42") + if err != nil { + t.Fatal(err) + } + t.Run(test.testName, func(t *testing.T) { req, err := getRequestFromEvent(test.event, dsn) if err != nil { t.Fatal(err)