2015-05-17 22:54:29 -07:00
|
|
|
package middleware
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/http/httptest"
|
|
|
|
"testing"
|
2015-05-30 10:54:55 -07:00
|
|
|
|
|
|
|
"github.com/labstack/echo"
|
|
|
|
"github.com/stretchr/testify/assert"
|
2015-05-17 22:54:29 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRecover(t *testing.T) {
|
|
|
|
e := echo.New()
|
2015-09-13 10:03:20 -07:00
|
|
|
e.SetDebug(true)
|
2015-05-17 22:54:29 -07:00
|
|
|
req, _ := http.NewRequest(echo.GET, "/", nil)
|
2015-05-30 10:54:55 -07:00
|
|
|
rec := httptest.NewRecorder()
|
2015-12-01 11:22:45 -08:00
|
|
|
c := echo.NewContext(req, echo.NewResponse(rec, e), e)
|
2015-05-20 14:38:51 -07:00
|
|
|
h := func(c *echo.Context) error {
|
2015-05-17 22:54:29 -07:00
|
|
|
panic("test")
|
|
|
|
}
|
|
|
|
Recover()(h)(c)
|
2015-05-30 10:54:55 -07:00
|
|
|
assert.Equal(t, http.StatusInternalServerError, rec.Code)
|
|
|
|
assert.Contains(t, rec.Body.String(), "panic recover")
|
2015-05-17 22:54:29 -07:00
|
|
|
}
|