Skip to content

Commit

Permalink
fix: PR review
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
AbhiPrasad committed Jun 3, 2020
1 parent f7555be commit 7c7ab9a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,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"`
Expand Down
27 changes: 18 additions & 9 deletions transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"sync/atomic"
"testing"
"time"

"github.com/google/go-cmp/cmp"
)

type unserializableType struct {
Expand All @@ -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",
Expand Down Expand Up @@ -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()
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7c7ab9a

Please sign in to comment.