From afb32ac6ac9f913898eda5701737e6a29e5c02ca Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Mon, 18 May 2015 20:51:08 +0200 Subject: [PATCH] Adds new unit test: static + middleware --- routes_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/routes_test.go b/routes_test.go index 3b5411b..12b5510 100644 --- a/routes_test.go +++ b/routes_test.go @@ -173,7 +173,24 @@ func TestRouteHeadToDir(t *testing.T) { assert.Contains(t, w.Body.String(), "gin.go") assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/html; charset=utf-8") } + +func TestRouterMiddlewareAndStatic(t *testing.T) { + router := New() + static := router.Group("/", func(c *Context) { + c.Writer.Header().Add("Last-Modified", "Mon, 02 Jan 2006 15:04:05 MST") + c.Writer.Header().Add("Expires", "Mon, 02 Jan 2006 15:04:05 MST") + c.Writer.Header().Add("X-GIN", "Gin Framework") + }) + static.Static("/", "./") + + w := performRequest(router, "GET", "/") + + assert.Equal(t, w.Code, 200) + assert.Contains(t, w.Body.String(), "gin.go") assert.Equal(t, w.HeaderMap.Get("Content-Type"), "text/html; charset=utf-8") + assert.NotEqual(t, w.HeaderMap.Get("Last-Modified"), "Mon, 02 Jan 2006 15:04:05 MST") + assert.Equal(t, w.HeaderMap.Get("Expires"), "Mon, 02 Jan 2006 15:04:05 MST") + assert.Equal(t, w.HeaderMap.Get("x-GIN"), "Gin Framework") } func TestRouteNotAllowed(t *testing.T) {