mirror of https://github.com/dexidp/dex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
803 B
52 lines
803 B
package time |
|
|
|
import ( |
|
"testing" |
|
"time" |
|
) |
|
|
|
func TestExpBackoff(t *testing.T) { |
|
tests := []struct { |
|
prev time.Duration |
|
max time.Duration |
|
want time.Duration |
|
}{ |
|
{ |
|
prev: time.Duration(0), |
|
max: time.Minute, |
|
want: time.Second, |
|
}, |
|
{ |
|
prev: time.Second, |
|
max: time.Minute, |
|
want: 2 * time.Second, |
|
}, |
|
{ |
|
prev: 16 * time.Second, |
|
max: time.Minute, |
|
want: 32 * time.Second, |
|
}, |
|
{ |
|
prev: 32 * time.Second, |
|
max: time.Minute, |
|
want: time.Minute, |
|
}, |
|
{ |
|
prev: time.Minute, |
|
max: time.Minute, |
|
want: time.Minute, |
|
}, |
|
{ |
|
prev: 2 * time.Minute, |
|
max: time.Minute, |
|
want: time.Minute, |
|
}, |
|
} |
|
|
|
for i, tt := range tests { |
|
got := ExpBackoff(tt.prev, tt.max) |
|
if tt.want != got { |
|
t.Errorf("case %d: want=%v got=%v", i, tt.want, got) |
|
} |
|
} |
|
}
|
|
|