Skip to content

Commit 1a5564a

Browse files
committed
Add unit test for parseRateLimitHeaders function
1 parent a02a1e8 commit 1a5564a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

httpclient/httpclient_rate_handler_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ func TestCalculateBackoff(t *testing.T) {
3535
}
3636
}
3737

38+
// TestParseRateLimitHeaders evaluates the functionality of the parseRateLimitHeaders function,
39+
// ensuring it correctly interprets various rate-limiting headers from an HTTP response and calculates
40+
// the appropriate wait duration. The function tests different scenarios including 'Retry-After' headers
41+
// with both date and delay values, 'X-RateLimit-Reset' headers indicating the reset time for rate limiting,
42+
// and situations where no relevant headers are present. Each test case mimics an HTTP response with specific
43+
// headers set, and asserts that the calculated wait duration falls within an acceptable range of the expected
44+
// value, allowing for slight variances due to execution time and rounding. The use of a mock logger ensures
45+
// that the function's logging behavior can also be verified without affecting the output of the test runner.
3846
func TestParseRateLimitHeaders(t *testing.T) {
3947
tests := []struct {
4048
name string

0 commit comments

Comments
 (0)