Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F114556
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/test/tesla/middleware/fuse_test.exs b/test/tesla/middleware/fuse_test.exs
index 8664096..18e0034 100644
--- a/test/tesla/middleware/fuse_test.exs
+++ b/test/tesla/middleware/fuse_test.exs
@@ -1,115 +1,111 @@
defmodule Tesla.Middleware.FuseTest do
use ExUnit.Case, async: false
defmodule Report do
def call(env, next, _) do
send(self(), :request_made)
Tesla.run(env, next)
end
end
defmodule Client do
use Tesla
plug Tesla.Middleware.Fuse
plug Report
adapter fn env ->
case env.url do
"/ok" ->
{:ok, env}
"/unavailable" ->
{:error, :econnrefused}
end
end
end
defmodule ClientWithCustomSetup do
use Tesla
plug Tesla.Middleware.Fuse,
keep_orig_error: true,
should_melt: fn
{:ok, %{status: status}} when status in [504] -> true
{:ok, _} -> false
{:error, _} -> true
end
plug Report
adapter fn env ->
case env.url do
"/ok" ->
{:ok, env}
"/error_500" ->
{:ok, %{env | status: 500}}
"/error_504" ->
{:ok, %{env | status: 504}}
"/unavailable" ->
{:error, :econnrefused}
end
end
end
setup do
Application.ensure_all_started(:fuse)
:fuse.reset(Client)
:fuse.reset(ClientWithCustomSetup)
:ok
end
test "regular endpoint" do
assert {:ok, %Tesla.Env{url: "/ok"}} = Client.get("/ok")
end
test "custom should_melt function - not melting 500" do
- custom_client = ClientWithCustomSetup
-
- assert {:ok, %Tesla.Env{status: 500}} = custom_client.get("/error_500")
+ assert {:ok, %Tesla.Env{status: 500}} = ClientWithCustomSetup.get("/error_500")
assert_receive :request_made
- assert {:ok, %Tesla.Env{status: 500}} = custom_client.get("/error_500")
+ assert {:ok, %Tesla.Env{status: 500}} = ClientWithCustomSetup.get("/error_500")
assert_receive :request_made
- assert {:ok, %Tesla.Env{status: 500}} = custom_client.get("/error_500")
+ assert {:ok, %Tesla.Env{status: 500}} = ClientWithCustomSetup.get("/error_500")
assert_receive :request_made
- assert {:ok, %Tesla.Env{status: 500}} = custom_client.get("/error_500")
+ assert {:ok, %Tesla.Env{status: 500}} = ClientWithCustomSetup.get("/error_500")
assert_receive :request_made
- assert {:ok, %Tesla.Env{status: 500}} = custom_client.get("/error_500")
+ assert {:ok, %Tesla.Env{status: 500}} = ClientWithCustomSetup.get("/error_500")
assert_receive :request_made
end
test "custom should_melt function - melting 504" do
- custom_client = ClientWithCustomSetup
-
- assert {:ok, %Tesla.Env{status: 504}} = custom_client.get("/error_504")
+ assert {:ok, %Tesla.Env{status: 504}} = ClientWithCustomSetup.get("/error_504")
assert_receive :request_made
- assert {:ok, %Tesla.Env{status: 504}} = custom_client.get("/error_504")
+ assert {:ok, %Tesla.Env{status: 504}} = ClientWithCustomSetup.get("/error_504")
assert_receive :request_made
- assert {:ok, %Tesla.Env{status: 504}} = custom_client.get("/error_504")
+ assert {:ok, %Tesla.Env{status: 504}} = ClientWithCustomSetup.get("/error_504")
assert_receive :request_made
- assert {:error, :unavailable} = custom_client.get("/error_504")
+ assert {:error, :unavailable} = ClientWithCustomSetup.get("/error_504")
refute_receive :request_made
- assert {:error, :unavailable} = custom_client.get("/error_504")
+ assert {:error, :unavailable} = ClientWithCustomSetup.get("/error_504")
refute_receive :request_made
end
test "unavailable endpoint" do
assert {:error, :unavailable} = Client.get("/unavailable")
assert_receive :request_made
assert {:error, :unavailable} = Client.get("/unavailable")
assert_receive :request_made
assert {:error, :unavailable} = Client.get("/unavailable")
assert_receive :request_made
assert {:error, :unavailable} = Client.get("/unavailable")
refute_receive :request_made
assert {:error, :unavailable} = Client.get("/unavailable")
refute_receive :request_made
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Tue, Nov 26, 11:35 AM (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40289
Default Alt Text
(4 KB)
Attached To
Mode
R28 tesla
Attached
Detach File
Event Timeline
Log In to Comment