fleet/pkg/retry/retry_test.go
Roberto Dip 15c93f02ea
add retry logic for native notarization and codesigning (#7806)
Related to #7130, this adds logic to retry native notarization up to three times if it fails for some reason.

Since we're adding retries in various places, I added a new package under pkg for this purpose.
2022-09-19 13:08:39 -03:00

42 lines
803 B
Go

package retry
import (
"errors"
"testing"
"time"
"github.com/stretchr/testify/require"
)
var errTest = errors.New("test error")
func TestRetryDo(t *testing.T) {
t.Run("WithMaxAttempts only performs the operation the configured number of times", func(t *testing.T) {
count := 0
max := 3
err := Do(func() error {
count++
return errTest
}, WithMaxAttempts(max), WithInterval(1*time.Millisecond))
require.ErrorIs(t, errTest, err)
require.Equal(t, max, count)
})
t.Run("operations are run an unlimited number of times by default", func(t *testing.T) {
count := 0
max := 10
err := Do(func() error {
if count++; count != max {
return errTest
}
return nil
}, WithInterval(1*time.Millisecond))
require.NoError(t, err)
require.Equal(t, max, count)
})
}