@@ -72,7 +72,29 @@ func TestRetryIf(t *testing.T) {
7272 assert .Len (t , err , 3 )
7373 assert .Equal (t , expectedErrorFormat , err .Error (), "retry error format" )
7474 assert .Equal (t , uint (2 ), retryCount , "right count of retry" )
75+ }
76+
77+ func TestRetryIf_ZeroAttempts (t * testing.T ) {
78+ var retryCount uint
79+ err := Do (
80+ func () error {
81+ if retryCount >= 2 {
82+ return errors .New ("special" )
83+ } else {
84+ return errors .New ("test" )
85+ }
86+ },
87+ OnRetry (func (n uint , err error ) { retryCount ++ }),
88+ RetryIf (func (err error ) bool {
89+ return err .Error () != "special"
90+ }),
91+ Delay (time .Nanosecond ),
92+ Attempts (0 ),
93+ )
94+ assert .Error (t , err )
7595
96+ assert .Equal (t , "special" , err .Error (), "retry error format" )
97+ assert .Equal (t , uint (2 ), retryCount , "right count of retry" )
7698}
7799
78100func TestZeroAttemptsWithError (t * testing.T ) {
@@ -504,6 +526,7 @@ func TestUnwrap(t *testing.T) {
504526 assert .Equal (t , testError , errors .Unwrap (err ))
505527}
506528
529+
507530func BenchmarkDo (b * testing.B ) {
508531 testError := errors .New ("test error" )
509532
@@ -529,3 +552,14 @@ func BenchmarkDoNoErrors(b *testing.B) {
529552 )
530553 }
531554}
555+
556+ func TestIsRecoverable (t * testing.T ) {
557+ err := errors .New ("err" )
558+ assert .True (t , IsRecoverable (err ))
559+
560+ err = Unrecoverable (err )
561+ assert .False (t , IsRecoverable (err ))
562+
563+ err = fmt .Errorf ("wrapping: %w" , err )
564+ assert .False (t , IsRecoverable (err ))
565+ }
0 commit comments