mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
bf85c56b08
Signed-off-by: Vishal Rana <vr@labstack.com>
37 lines
751 B
Go
37 lines
751 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 = echo.NewContext(req, echo.NewResponse(w), e)
|
|
h = func(c *echo.Context) error {
|
|
return c.String(http.StatusNotFound, "test")
|
|
}
|
|
Logger()(h)(c)
|
|
|
|
// Status 5xx
|
|
c = echo.NewContext(req, echo.NewResponse(w), e)
|
|
h = func(c *echo.Context) error {
|
|
return c.String(http.StatusInternalServerError, "test")
|
|
}
|
|
Logger()(h)(c)
|
|
}
|