-
Notifications
You must be signed in to change notification settings - Fork 0
/
package_test.go
45 lines (37 loc) · 877 Bytes
/
package_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
package retry_test
import (
"context"
"testing"
"github.com/shogo82148/go-retry/v2"
)
type customError bool
func (err customError) Error() string {
if bool(err) {
return "temporary error"
}
return "permanent error"
}
// The temporary method will be ignored by the retry package.
func (err customError) temporary() bool {
return bool(err)
}
func TestDo_WithPermanentError(t *testing.T) {
if customError(false).temporary() != false {
t.Errorf("want false, got true")
}
policy := &retry.Policy{
MaxCount: 10,
}
var count int
err := policy.Do(context.Background(), func() error {
count++
return customError(false)
})
if err != customError(false) {
t.Errorf("want error is %#v, got %#v", err, customError(false))
}
// defining the temporary method out of the package will not work
if count != 10 {
t.Errorf("want %d, got %d", 10, count)
}
}