Added test for requests to / when no route for / is defined
This commit is contained in:
parent
a0ae5c296d
commit
70593e8dfe
18
gin_test.go
18
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)
|
||||
|
Loading…
Reference in New Issue
Block a user