Skip to content

Commit

Permalink
fix failing router tests (#360)
Browse files Browse the repository at this point in the history
* fix failing router tests

* add missing comment
  • Loading branch information
mthenw authored Feb 12, 2018
1 parent 7907ff2 commit 773adad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions internal/httpapi/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package httpapi

import "fmt"

// Response is a generic response object from Configuration and Events API.
type Response struct {
Errors []Error `json:"errors"`
}
Expand Down
10 changes: 5 additions & 5 deletions router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestRouterServeHTTP_StatusUnavailableWhenDraining(t *testing.T) {
router.ServeHTTP(recorder, req)

assert.Equal(t, http.StatusServiceUnavailable, recorder.Code)
assert.Equal(t, "Service Unavailable\n", recorder.Body.String())
assert.Equal(t, `{"errors":[{"message":"Service Unavailable"}]}`+"\n", recorder.Body.String())
}

func TestRouterServeHTTP_HTTPEventFunctionNotFound(t *testing.T) {
Expand All @@ -46,7 +46,7 @@ func TestRouterServeHTTP_HTTPEventFunctionNotFound(t *testing.T) {
router.ServeHTTP(recorder, req)

assert.Equal(t, http.StatusNotFound, recorder.Code)
assert.Equal(t, "resource not found\n", recorder.Body.String())
assert.Equal(t, `{"errors":[{"message":"resource not found"}]}`+"\n", recorder.Body.String())
}

func TestRouterServeHTTP_InvokeEventFunctionNotFound(t *testing.T) {
Expand All @@ -65,7 +65,7 @@ func TestRouterServeHTTP_InvokeEventFunctionNotFound(t *testing.T) {
router.ServeHTTP(recorder, req)

assert.Equal(t, http.StatusInternalServerError, recorder.Code)
assert.Equal(t, "unable to look up registered function\n", recorder.Body.String())
assert.Equal(t, `{"errors":[{"message":"unable to look up registered function"}]}`+"\n", recorder.Body.String())
}

func TestRouterServeHTTP_ErrorMalformedCustomEventJSONRequest(t *testing.T) {
Expand All @@ -80,7 +80,7 @@ func TestRouterServeHTTP_ErrorMalformedCustomEventJSONRequest(t *testing.T) {
router.ServeHTTP(recorder, req)

assert.Equal(t, http.StatusBadRequest, recorder.Code)
assert.Equal(t, "malformed JSON body\n", recorder.Body.String())
assert.Equal(t, `{"errors":[{"message":"malformed JSON body"}]}`+"\n", recorder.Body.String())
}

func TestRouterServeHTTP_ErrorOnCustomEventEmittedWithNonPostMethod(t *testing.T) {
Expand All @@ -96,7 +96,7 @@ func TestRouterServeHTTP_ErrorOnCustomEventEmittedWithNonPostMethod(t *testing.T
router.ServeHTTP(recorder, req)

assert.Equal(t, http.StatusBadRequest, recorder.Code)
assert.Equal(t, "custom event can be emitted only with POST method\n", recorder.Body.String())
assert.Equal(t, `{"errors":[{"message":"custom event can be emitted only with POST method"}]}`+"\n", recorder.Body.String())
}

func TestRouterServeHTTP_AllowCORSPreflightForHTTPEventWhenConfigured(t *testing.T) {
Expand Down

0 comments on commit 773adad

Please sign in to comment.