32 lines
612 B
Go
32 lines
612 B
Go
package scrobble
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestBackoffDelay(t *testing.T) {
|
|
cases := []struct {
|
|
attempts int
|
|
want time.Duration
|
|
ok bool
|
|
}{
|
|
{1, 1 * time.Minute, true},
|
|
{2, 5 * time.Minute, true},
|
|
{3, 30 * time.Minute, true},
|
|
{4, 2 * time.Hour, true},
|
|
{5, 6 * time.Hour, true},
|
|
{6, 0, false},
|
|
{99, 0, false},
|
|
}
|
|
for _, c := range cases {
|
|
got, ok := backoffDelay(c.attempts)
|
|
if ok != c.ok {
|
|
t.Errorf("backoffDelay(%d) ok = %v, want %v", c.attempts, ok, c.ok)
|
|
}
|
|
if got != c.want {
|
|
t.Errorf("backoffDelay(%d) = %v, want %v", c.attempts, got, c.want)
|
|
}
|
|
}
|
|
}
|