-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecovery_error_test.go
40 lines (30 loc) · 966 Bytes
/
recovery_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
package recovererr
import (
"errors"
"testing"
"github.com/stretchr/testify/assert"
)
func TestUnwrap(t *testing.T) {
t.Parallel()
t.Run("recoverable connection error", func(t *testing.T) {
var connectionError = errors.New("connection error")
err := recoveryError{recover: true, err: connectionError}
assert.Equal(t, connectionError, errors.Unwrap(err))
})
t.Run("unrecoverable wrapped error", func(t *testing.T) {
var ParseError = errors.New("parse error")
err := Unrecoverable(ParseError)
assert.Equal(t, ParseError, errors.Unwrap(err))
})
}
func TestrecoveryError_Error(t *testing.T) {
t.Parallel()
t.Run("recoverable error", func(t *testing.T) {
re := &recoveryError{recover: true, err: errors.New("test")}
assert.Equal(t, "recover: test", re.Error())
})
t.Run("unrecoverable error", func(t *testing.T) {
re := &recoveryError{recover: false, err: errors.New("test")}
assert.Equal(t, "unrecover: test", re.Error())
})
}