From 773adad2685c1eeb4fa6175ab586aa0bce4c3232 Mon Sep 17 00:00:00 2001 From: Maciej Winnicki Date: Mon, 12 Feb 2018 11:24:47 +0100 Subject: [PATCH] fix failing router tests (#360) * fix failing router tests * add missing comment --- internal/httpapi/error.go | 1 + router/router_test.go | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/internal/httpapi/error.go b/internal/httpapi/error.go index 46fe956..29d3843 100644 --- a/internal/httpapi/error.go +++ b/internal/httpapi/error.go @@ -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"` } diff --git a/router/router_test.go b/router/router_test.go index 1ef2683..b669d17 100644 --- a/router/router_test.go +++ b/router/router_test.go @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) {