Skip to content

Commit eb0f76e

Browse files
jeremyrosa
authored andcommitted
Cover Retry-After parsing directly
Delta-seconds, numerics, HTTP-dates (past dates clamp to zero), unparseable values reading as nil, and the message falling back to the reason token.
1 parent fffea16 commit eb0f76e

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require "test_helper"
2+
3+
module ActionPushNative
4+
class ErrorsTest < ActiveSupport::TestCase
5+
test "retry_after accepts delta-seconds, numerics, and nil" do
6+
assert_equal 30, TooManyRequestsError.new(retry_after: "30").retry_after
7+
assert_equal 2.5, TooManyRequestsError.new(retry_after: 2.5).retry_after
8+
assert_nil TooManyRequestsError.new.retry_after
9+
end
10+
11+
test "retry_after accepts an HTTP-date, clamping past dates to zero" do
12+
freeze_time do
13+
error = ServiceUnavailableError.new(retry_after: 42.seconds.from_now.httpdate)
14+
assert_in_delta 42.0, error.retry_after, 1.0
15+
16+
assert_equal 0.0, ServiceUnavailableError.new(retry_after: 1.hour.ago.httpdate).retry_after
17+
end
18+
end
19+
20+
test "an unparseable Retry-After reads as nil" do
21+
assert_nil TooManyRequestsError.new(retry_after: "soon").retry_after
22+
end
23+
24+
test "the message stays the first positional argument, falling back to the reason" do
25+
assert_equal "boom", TooManyRequestsError.new("boom", reason: "QUOTA_EXCEEDED").message
26+
assert_equal "QUOTA_EXCEEDED", TooManyRequestsError.new(reason: "QUOTA_EXCEEDED").message
27+
end
28+
end
29+
end

0 commit comments

Comments
 (0)