1
0
mirror of https://github.com/IBM/fp-go.git synced 2025-08-10 22:31:32 +02:00
Files
fp-go/io/retry_test.go
Dr. Carsten Leue b25de3c7c3 doc: fix case
Signed-off-by: Dr. Carsten Leue <carsten.leue@de.ibm.com>
2023-07-18 15:57:54 +02:00

33 lines
623 B
Go

package io
import (
"fmt"
"strings"
"testing"
"time"
R "github.com/IBM/fp-go/retry"
"github.com/stretchr/testify/assert"
)
var expLogBackoff = R.ExponentialBackoff(10)
// our retry policy with a 1s cap
var testLogPolicy = R.CapDelay(
2*time.Second,
R.Monoid.Concat(expLogBackoff, R.LimitRetries(20)),
)
func TestRetry(t *testing.T) {
action := func(status R.RetryStatus) IO[string] {
return Of(fmt.Sprintf("Retrying %d", status.IterNumber))
}
check := func(value string) bool {
return !strings.Contains(value, "5")
}
r := Retrying(testLogPolicy, action, check)
assert.Equal(t, "Retrying 5", r())
}