1
0
mirror of https://github.com/labstack/echo.git synced 2024-11-24 08:22:21 +02:00

Add tests for HTTPError.Unwrap

This commit is contained in:
Jonathan Hall 2020-05-05 16:18:16 +02:00
parent 803c4f673b
commit ea34bf9441
2 changed files with 28 additions and 1 deletions

28
echo_go1.13_test.go Normal file
View File

@ -0,0 +1,28 @@
// +build go1.13
package echo
import (
"errors"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
)
func TestHTTPError_Unwrap(t *testing.T) {
t.Run("non-internal", func(t *testing.T) {
err := NewHTTPError(http.StatusBadRequest, map[string]interface{}{
"code": 12,
})
assert.Nil(t, errors.Unwrap(err))
})
t.Run("internal", func(t *testing.T) {
err := NewHTTPError(http.StatusBadRequest, map[string]interface{}{
"code": 12,
})
err.SetInternal(errors.New("internal error"))
assert.Equal(t, "internal error", errors.Unwrap(err).Error())
})
}

View File

@ -549,7 +549,6 @@ func TestHTTPError(t *testing.T) {
}) })
assert.Equal(t, "code=400, message=map[code:12]", err.Error()) assert.Equal(t, "code=400, message=map[code:12]", err.Error())
}) })
t.Run("internal", func(t *testing.T) { t.Run("internal", func(t *testing.T) {
err := NewHTTPError(http.StatusBadRequest, map[string]interface{}{ err := NewHTTPError(http.StatusBadRequest, map[string]interface{}{