From 71bb9ae0c94f1156db50246b29dfa193e64ce611 Mon Sep 17 00:00:00 2001 From: Stefan Lapers Date: Thu, 18 Jul 2024 11:13:26 +0200 Subject: [PATCH] Use `:finch` value to override finch instance (#391) --- lib/req/finch.ex | 8 ++++++-- test/req/finch_test.exs | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/req/finch.ex b/lib/req/finch.ex index b4ced49..e24a2c9 100644 --- a/lib/req/finch.ex +++ b/lib/req/finch.ex @@ -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) diff --git a/test/req/finch_test.exs b/test/req/finch_test.exs index 15d5822..285b534 100644 --- a/test/req/finch_test.exs +++ b/test/req/finch_test.exs @@ -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])