From f7e947707a1bd78b4603418fedcc41b6d54988c8 Mon Sep 17 00:00:00 2001 From: "Daniel G. Taylor" Date: Thu, 21 Apr 2022 23:29:44 -0700 Subject: [PATCH] test: add default repsonse test --- router_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/router_test.go b/router_test.go index d69fbbf..626210b 100644 --- a/router_test.go +++ b/router_test.go @@ -462,3 +462,19 @@ func TestSubResource(t *testing.T) { // Do nothing }) } + +func TestDefaultResponse(t *testing.T) { + app := newTestRouter() + + // This should not crash. + app.Resource("/").Get("get-root", "docs", NewResponse(0, "Default repsonse")).Run(func(ctx Context) { + ctx.WriteHeader(http.StatusOK) + }) + + w := httptest.NewRecorder() + req, _ := http.NewRequest(http.MethodGet, "/", nil) + app.ServeHTTP(w, req) + + // This should not panic and should return the 200 OK + assert.Equal(t, http.StatusOK, w.Result().StatusCode) +}