-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
error_test.go
46 lines (34 loc) · 941 Bytes
/
error_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package sprout
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestErrRecoverPanic(t *testing.T) {
err := errors.New("test error")
errMessage := "panic occurred"
require.NotPanics(t, func() {
defer ErrRecoverPanic(&err, errMessage)
panic("test panic")
})
require.Error(t, err)
assert.ErrorContains(t, err, errMessage)
}
func TestErrRecoverPanic_NoPanic(t *testing.T) {
var err error
errMessage := "panic occurred"
defer ErrRecoverPanic(&err, errMessage)
require.NoError(t, err)
}
func TestErrConvertFailed(t *testing.T) {
baseErr := errors.New("test error")
typ := "string"
value := 1
err := NewErrConvertFailed(typ, value, baseErr)
require.Error(t, err)
require.ErrorContains(t, err, "failed to convert: 1 to string")
require.ErrorContains(t, err, "test error")
require.ErrorIs(t, err, ErrConvertFailed)
require.ErrorIs(t, err, baseErr)
}