1
0
mirror of https://github.com/labstack/echo.git synced 2024-12-20 19:52:47 +02:00
echo/middleware/logger_test.go
Vishal Rana 13ac746093 Refactored Echo.HandlerFunc, added WebSocket support.
Signed-off-by: Vishal Rana <vr@labstack.com>
2015-05-20 14:38:51 -07:00

37 lines
719 B
Go

package middleware
import (
"github.com/labstack/echo"
"net/http"
"net/http/httptest"
"testing"
)
func TestLogger(t *testing.T) {
e := echo.New()
req, _ := http.NewRequest(echo.GET, "/", nil)
w := httptest.NewRecorder()
res := echo.NewResponse(w)
c := echo.NewContext(req, res, e)
// Status 2xx
h := func(c *echo.Context) error {
return c.String(http.StatusOK, "test")
}
Logger()(h)(c)
// Status 4xx
c.Response = echo.NewResponse(w)
h = func(c *echo.Context) error {
return c.String(http.StatusNotFound, "test")
}
Logger()(h)(c)
// Status 5xx
c.Response = echo.NewResponse(w)
h = func(c *echo.Context) error {
return c.String(http.StatusInternalServerError, "test")
}
Logger()(h)(c)
}