Skip to content

Commit ea34bf9

Browse files
committed
Add tests for HTTPError.Unwrap
1 parent 803c4f6 commit ea34bf9

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

echo_go1.13_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// +build go1.13
2+
3+
package echo
4+
5+
import (
6+
"errors"
7+
"net/http"
8+
"testing"
9+
10+
"github.com/stretchr/testify/assert"
11+
)
12+
13+
func TestHTTPError_Unwrap(t *testing.T) {
14+
t.Run("non-internal", func(t *testing.T) {
15+
err := NewHTTPError(http.StatusBadRequest, map[string]interface{}{
16+
"code": 12,
17+
})
18+
19+
assert.Nil(t, errors.Unwrap(err))
20+
})
21+
t.Run("internal", func(t *testing.T) {
22+
err := NewHTTPError(http.StatusBadRequest, map[string]interface{}{
23+
"code": 12,
24+
})
25+
err.SetInternal(errors.New("internal error"))
26+
assert.Equal(t, "internal error", errors.Unwrap(err).Error())
27+
})
28+
}

echo_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,6 @@ func TestHTTPError(t *testing.T) {
549549
})
550550

551551
assert.Equal(t, "code=400, message=map[code:12]", err.Error())
552-
553552
})
554553
t.Run("internal", func(t *testing.T) {
555554
err := NewHTTPError(http.StatusBadRequest, map[string]interface{}{

0 commit comments

Comments
 (0)