From 70593e8dfe8874034a07157eaab169c948b7dd6d Mon Sep 17 00:00:00 2001 From: Alexander Nyquist Date: Fri, 4 Jul 2014 11:01:11 +0200 Subject: [PATCH] Added test for requests to / when no route for / is defined --- gin_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/gin_test.go b/gin_test.go index eb6ccce..e66c5e3 100644 --- a/gin_test.go +++ b/gin_test.go @@ -29,6 +29,24 @@ func TestRouterGroupGETRouteOK(t *testing.T) { } } +// TestRouterGroupGETNoRootExistsRouteOK tests that a GET requse to root is correctly +// handled (404) when no root route exists. +func TestRouterGroupGETNoRootExistsRouteOK(t *testing.T) { + req, _ := http.NewRequest("GET", "/", nil) + w := httptest.NewRecorder() + + r := Default() + r.GET("/test", func (c *Context) { + }) + + r.ServeHTTP(w, req) + + if w.Code != http.StatusNotFound { + // If this fails, it's because httprouter needs to be updated to at least f78f58a0db + t.Errorf("Status code should be %v, was %d. Location: %s", http.StatusNotFound, w.Code, w.HeaderMap.Get("Location")) + } +} + // TestRouterGroupPOSTRouteOK tests that POST route is correctly invoked. func TestRouterGroupPOSTRouteOK(t *testing.T) { req, _ := http.NewRequest("POST", "/test", nil)