Skip to content

Commit

Permalink
tests: add test cases for parseRetryAfterHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
justenwalker committed Aug 13, 2021
1 parent 0ed3cd7 commit 28eff18
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,35 @@ func testStaticTime(t *testing.T) {
})
}

func TestParseRetryAfterHeader(t *testing.T) {
testStaticTime(t)
tests := []struct {
name string
headers []string
sleep time.Duration
ok bool
}{
{"seconds", []string{"2"}, time.Second * 2, true},
{"date", []string{"Fri, 31 Dec 1999 23:59:59 GMT"}, time.Second * 2, true},
{"past-date", []string{"Fri, 31 Dec 1999 23:59:00 GMT"}, 0, true},
{"empty", []string{""}, 0, false},
{"negative", []string{"-2"}, 0, false},
{"bad-date", []string{"Fri, 32 Dec 1999 23:59:59 GMT"}, 0, false},
{"bad-date-format", []string{"badbadbad"}, 0, false},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
sleep, ok := parseRetryAfterHeader(test.headers)
if ok != test.ok {
t.Fatalf("expected ok=%t, got ok=%t", test.ok, ok)
}
if sleep != test.sleep {
t.Fatalf("expected sleep=%v, got sleep=%v", test.sleep, sleep)
}
})
}
}

func TestClient_DefaultBackoff(t *testing.T) {
testStaticTime(t)
tests := []struct {
Expand Down

0 comments on commit 28eff18

Please sign in to comment.