@@ -85,7 +85,29 @@ func TestRetryIf(t *testing.T) {
8585 assert .Len (t , err , 3 )
8686 assert .Equal (t , expectedErrorFormat , err .Error (), "retry error format" )
8787 assert .Equal (t , uint (2 ), retryCount , "right count of retry" )
88+ }
89+
90+ func TestRetryIf_ZeroAttempts (t * testing.T ) {
91+ var retryCount uint
92+ err := Do (
93+ func () error {
94+ if retryCount >= 2 {
95+ return errors .New ("special" )
96+ } else {
97+ return errors .New ("test" )
98+ }
99+ },
100+ OnRetry (func (n uint , err error ) { retryCount ++ }),
101+ RetryIf (func (err error ) bool {
102+ return err .Error () != "special"
103+ }),
104+ Delay (time .Nanosecond ),
105+ Attempts (0 ),
106+ )
107+ assert .Error (t , err )
88108
109+ assert .Equal (t , "special" , err .Error (), "retry error format" )
110+ assert .Equal (t , uint (2 ), retryCount , "right count of retry" )
89111}
90112
91113func TestZeroAttemptsWithError (t * testing.T ) {
@@ -516,3 +538,14 @@ func TestUnwrap(t *testing.T) {
516538 assert .Error (t , err )
517539 assert .Equal (t , testError , errors .Unwrap (err ))
518540}
541+
542+ func TestIsRecoverable (t * testing.T ) {
543+ err := errors .New ("err" )
544+ assert .True (t , IsRecoverable (err ))
545+
546+ err = Unrecoverable (err )
547+ assert .False (t , IsRecoverable (err ))
548+
549+ err = fmt .Errorf ("wrapping: %w" , err )
550+ assert .False (t , IsRecoverable (err ))
551+ }
0 commit comments