[#2250] Tiny refactoring per merge request review.
This commit is contained in:
parent
3759b146c4
commit
c747260989
|
@ -121,6 +121,8 @@ def disabled? do
|
||||||
localhost_or_socket and remote_ip_disabled
|
localhost_or_socket and remote_ip_disabled
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@inspect_bucket_not_found {:error, :not_found}
|
||||||
|
|
||||||
def inspect_bucket(conn, bucket_name_root, plug_opts) do
|
def inspect_bucket(conn, bucket_name_root, plug_opts) do
|
||||||
with %{name: _} = action_settings <- action_settings(plug_opts) do
|
with %{name: _} = action_settings <- action_settings(plug_opts) do
|
||||||
action_settings = incorporate_conn_info(action_settings, conn)
|
action_settings = incorporate_conn_info(action_settings, conn)
|
||||||
|
@ -130,7 +132,7 @@ def inspect_bucket(conn, bucket_name_root, plug_opts) do
|
||||||
|
|
||||||
case Cachex.get(bucket_name, key_name) do
|
case Cachex.get(bucket_name, key_name) do
|
||||||
{:error, :no_cache} ->
|
{:error, :no_cache} ->
|
||||||
{:err, :not_found}
|
@inspect_bucket_not_found
|
||||||
|
|
||||||
{:ok, nil} ->
|
{:ok, nil} ->
|
||||||
{0, limit}
|
{0, limit}
|
||||||
|
@ -139,7 +141,7 @@ def inspect_bucket(conn, bucket_name_root, plug_opts) do
|
||||||
{value, limit - value}
|
{value, limit - value}
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
_ -> {:err, :not_found}
|
_ -> @inspect_bucket_not_found
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -109,7 +109,7 @@ test "`bucket_name` option overrides default bucket name" do
|
||||||
|
|
||||||
RateLimiter.call(conn, plug_opts)
|
RateLimiter.call(conn, plug_opts)
|
||||||
assert {1, 4} = RateLimiter.inspect_bucket(conn, base_bucket_name, plug_opts)
|
assert {1, 4} = RateLimiter.inspect_bucket(conn, base_bucket_name, plug_opts)
|
||||||
assert {:err, :not_found} = RateLimiter.inspect_bucket(conn, limiter_name, plug_opts)
|
assert {:error, :not_found} = RateLimiter.inspect_bucket(conn, limiter_name, plug_opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "`params` option allows different queries to be tracked independently" do
|
test "`params` option allows different queries to be tracked independently" do
|
||||||
|
|
Loading…
Reference in New Issue