mirror of
https://github.com/labstack/echo.git
synced 2025-12-01 22:51:17 +02:00
@@ -8,7 +8,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/labstack/echo"
|
||||
"github.com/labstack/gommon/log"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -17,7 +16,7 @@ func TestLogger(t *testing.T) {
|
||||
e := echo.New()
|
||||
req, _ := http.NewRequest(echo.GET, "/", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
c := echo.NewContext(req, echo.NewResponse(rec), e)
|
||||
c := echo.NewContext(req, echo.NewResponse(rec, e), e)
|
||||
|
||||
// Status 2xx
|
||||
h := func(c *echo.Context) error {
|
||||
@@ -27,7 +26,7 @@ func TestLogger(t *testing.T) {
|
||||
|
||||
// Status 3xx
|
||||
rec = httptest.NewRecorder()
|
||||
c = echo.NewContext(req, echo.NewResponse(rec), e)
|
||||
c = echo.NewContext(req, echo.NewResponse(rec, e), e)
|
||||
h = func(c *echo.Context) error {
|
||||
return c.String(http.StatusTemporaryRedirect, "test")
|
||||
}
|
||||
@@ -35,7 +34,7 @@ func TestLogger(t *testing.T) {
|
||||
|
||||
// Status 4xx
|
||||
rec = httptest.NewRecorder()
|
||||
c = echo.NewContext(req, echo.NewResponse(rec), e)
|
||||
c = echo.NewContext(req, echo.NewResponse(rec, e), e)
|
||||
h = func(c *echo.Context) error {
|
||||
return c.String(http.StatusNotFound, "test")
|
||||
}
|
||||
@@ -44,7 +43,7 @@ func TestLogger(t *testing.T) {
|
||||
// Status 5xx with empty path
|
||||
req, _ = http.NewRequest(echo.GET, "", nil)
|
||||
rec = httptest.NewRecorder()
|
||||
c = echo.NewContext(req, echo.NewResponse(rec), e)
|
||||
c = echo.NewContext(req, echo.NewResponse(rec, e), e)
|
||||
h = func(c *echo.Context) error {
|
||||
return errors.New("error")
|
||||
}
|
||||
@@ -52,14 +51,13 @@ func TestLogger(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoggerIPAddress(t *testing.T) {
|
||||
buf := &bytes.Buffer{}
|
||||
log.SetOutput(buf)
|
||||
ip := "127.0.0.1"
|
||||
|
||||
e := echo.New()
|
||||
req, _ := http.NewRequest(echo.GET, "/", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
c := echo.NewContext(req, echo.NewResponse(rec), e)
|
||||
c := echo.NewContext(req, echo.NewResponse(rec, e), e)
|
||||
buf := new(bytes.Buffer)
|
||||
e.Logger().SetOutput(buf)
|
||||
ip := "127.0.0.1"
|
||||
h := func(c *echo.Context) error {
|
||||
return c.String(http.StatusOK, "test")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user