Refactor doRetry() tests

Refactor tests to use table tests and add a new case were a normal error is
returned.
parent 337e5732
Pipeline #52152256 passed with stages
in 27 minutes and 33 seconds
......@@ -7,30 +7,43 @@ import (
"github.com/stretchr/testify/assert"
)
func TestDoRetryError(t *testing.T) {
r := retryHelper{
Retry: 3,
func TestDoRetry(t *testing.T) {
cases := []struct {
name string
err error
expectedCount int
}{
{
name: "Error is of type retryableErr",
err: retryableErr{err: errors.New("error")},
expectedCount: 4,
},
{
name: "Error is not type of retryableErr",
err: errors.New("error"),
expectedCount: 1,
},
{
name: "Error is nil",
err: nil,
expectedCount: 1,
},
}
retryCount := 0
err := r.doRetry(func() error {
retryCount++
return retryableErr{err: errors.New("error")}
})
assert.Error(t, err)
assert.Equal(t, r.Retry+1, retryCount)
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
r := retryHelper{
Retry: 3,
}
func TestDoRetry(t *testing.T) {
r := retryHelper{
Retry: 3,
}
retryCount := 0
err := r.doRetry(func() error {
retryCount++
return c.err
})
retryCount := 0
err := r.doRetry(func() error {
retryCount++
return nil
})
assert.NoError(t, err)
assert.Equal(t, 1, retryCount)
assert.Equal(t, c.err, err)
assert.Equal(t, c.expectedCount, retryCount)
})
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment