-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
func_test.go
51 lines (43 loc) · 915 Bytes
/
func_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
47
48
49
50
51
package keys_test
import (
"testing"
"github.com/keys-pub/keys"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
)
type testRetry struct {
attempt int
wrap bool
}
func (t *testRetry) fn() error {
t.attempt = t.attempt + 1
if t.attempt == 1 {
if t.wrap {
return errors.Wrapf(&errTest{}, "failed on attempt %d", t.attempt)
}
return &errTest{}
}
return nil
}
func TestRetryEDefault(t *testing.T) {
tr := &testRetry{}
err := keys.RetryE(tr.fn)
require.NoError(t, err)
}
func TestRetryError(t *testing.T) {
err := keys.RetryE(func() error {
return errors.Errorf("error")
})
require.Error(t, err)
}
func TestRetrySError(t *testing.T) {
_, err := keys.RetrySE(func() (string, error) {
return "", errors.Errorf("error")
})
require.Error(t, err)
}
func TestRetryEWrap(t *testing.T) {
tr := &testRetry{wrap: true}
err := keys.RetryE(tr.fn)
require.NoError(t, err)
}