Skip to content

Commit

Permalink
Use :finch value to override finch instance (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
slapers authored Jul 18, 2024
1 parent ef8bd82 commit 71bb9ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/req/finch.ex
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,12 @@ defmodule Req.Finch do
Map.has_key?(request.options, :connect_options) or Map.has_key?(request.options, :inet6)

cond do
request.options[:finch] && custom_options? ->
raise ArgumentError, "cannot set both :finch and :connect_options"
name = request.options[:finch] ->
if custom_options? do
raise ArgumentError, "cannot set both :finch and :connect_options"
else
name
end

custom_options? ->
pool_options = pool_options(request.options)
Expand Down
6 changes: 6 additions & 0 deletions test/req/finch_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ defmodule Req.FinchTest do
end
end

test ":finch option" do
assert_raise ArgumentError, "unknown registry: MyFinch", fn ->
Req.get!("http://localhost", finch: MyFinch)
end
end

test ":finch and :connect_options" do
assert_raise ArgumentError, "cannot set both :finch and :connect_options", fn ->
Req.request!(finch: MyFinch, connect_options: [timeout: 0])
Expand Down

0 comments on commit 71bb9ae

Please sign in to comment.