Skip to content

Commit

Permalink
Allow *revel.Http structs in http_request field (#33)
Browse files Browse the repository at this point in the history
* Update getHTTPRequest() to return a *raven.Http struct

* Accept *raven.Http structs in http_request field
  • Loading branch information
flimzy authored and evalphobia committed Jan 1, 2017
1 parent 3192a93 commit 02fca77
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
6 changes: 5 additions & 1 deletion data_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ func (d *dataField) getError() (error, bool) {
return nil, false
}

func (d *dataField) getHTTPRequest() (*http.Request, bool) {
func (d *dataField) getHTTPRequest() (*raven.Http, bool) {
if req, ok := d.data[fieldHTTPRequest].(*http.Request); ok {
d.omitList[fieldHTTPRequest] = struct{}{}
return raven.NewHttp(req), true
}
if req, ok := d.data[fieldHTTPRequest].(*raven.Http); ok {
d.omitList[fieldHTTPRequest] = struct{}{}
return req, true
}
Expand Down
11 changes: 8 additions & 3 deletions data_field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,19 +221,24 @@ func TestGetError(t *testing.T) {
func TestGetHTTPRequest(t *testing.T) {
assert := assert.New(t)

httpReq, _ := http.NewRequest("GET", "/", nil)
ravenReq := raven.NewHttp(httpReq)

tests := []struct {
key string
value interface{}
expected bool
description string
}{
{"http_request", &http.Request{}, true, "valid http_request"},
{"not_http_request", &http.Request{}, false, "invalid key"},
{"http_request", httpReq, true, "valid http_request"},
{"not_http_request", httpReq, false, "invalid key"},
{"http_request", http.Request{}, false, "invalid value type"},
{"http_request", "test_http_request", false, "invalid value type"},
{"http_request", 1, false, "invalid value type"},
{"http_request", true, false, "invalid value type"},
{"http_request", struct{}{}, false, "invalid value type"},
{"http_request", raven.NewHttp(httpReq), true, "valid raven http_request"},
{"http_request", raven.Http{}, false, "invalid raven http_request"},
}

for _, tt := range tests {
Expand All @@ -246,7 +251,7 @@ func TestGetHTTPRequest(t *testing.T) {
req, ok := df.getHTTPRequest()
assert.Equal(tt.expected, ok, target)
if ok {
assert.Equal(tt.value, req, target)
assert.Equal(ravenReq, req, target)
assert.True(df.isOmit("http_request"), "`http_request` should be in omitList")
} else {
assert.False(df.isOmit("http_request"), "`http_request` should not be in omitList")
Expand Down
2 changes: 1 addition & 1 deletion sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (hook *SentryHook) Fire(entry *logrus.Entry) error {
packet.Tags = tags
}
if req, ok := df.getHTTPRequest(); ok {
packet.Interfaces = append(packet.Interfaces, raven.NewHttp(req))
packet.Interfaces = append(packet.Interfaces, req)
}
if user, ok := df.getUser(); ok {
packet.Interfaces = append(packet.Interfaces, user)
Expand Down

0 comments on commit 02fca77

Please sign in to comment.