Skip to content

Commit

Permalink
Add tests for HTTPError.Unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
flimzy committed May 5, 2020
1 parent 803c4f6 commit ea34bf9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
28 changes: 28 additions & 0 deletions echo_go1.13_test.go
Original file line number Diff line number Diff line change
@@ -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())
})
}
1 change: 0 additions & 1 deletion echo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,6 @@ func TestHTTPError(t *testing.T) {
})

assert.Equal(t, "code=400, message=map[code:12]", err.Error())

})
t.Run("internal", func(t *testing.T) {
err := NewHTTPError(http.StatusBadRequest, map[string]interface{}{
Expand Down

0 comments on commit ea34bf9

Please sign in to comment.