Page MenuHomePhorge

No OneTemporary

Size
3 KB
Referenced Files
None
Subscribers
None
diff --git a/test/tesla/adapter/gun_test.exs b/test/tesla/adapter/gun_test.exs
index 6c1066a..eba4770 100644
--- a/test/tesla/adapter/gun_test.exs
+++ b/test/tesla/adapter/gun_test.exs
@@ -1,131 +1,132 @@
defmodule Tesla.Adapter.GunTest do
use ExUnit.Case
use Tesla.AdapterCase, adapter: Tesla.Adapter.Gun
use Tesla.AdapterCase.Basic
use Tesla.AdapterCase.Multipart
use Tesla.AdapterCase.StreamRequestBody
use Tesla.AdapterCase.SSL
+ alias Tesla.Adapter.Gun
test "fallback adapter timeout option" do
request = %Env{
method: :get,
url: "#{@http}/delay/2"
}
assert {:error, :timeout} = call(request, timeout: 1_000)
end
test "max_body option" do
request = %Env{
method: :get,
url: "#{@http}/get",
query: [
message: "Hello world!"
]
}
assert {:error, :body_too_large} = call(request, max_body: 5)
end
test "without slash" do
request = %Env{
method: :get,
url: "#{@http}"
}
assert {:ok, %Env{} = response} = call(request)
assert response.status == 400
end
test "response stream" do
request = %Env{
method: :get,
url: "#{@http}/stream-bytes/10"
}
assert {:ok, %Env{} = response} = call(request)
assert response.status == 200
assert byte_size(response.body) == 16
end
test "read response body in chunks" do
request = %Env{
method: :get,
url: "#{@http}/stream-bytes/10"
}
assert {:ok, %Env{} = response} = call(request, body_as: :chunks)
assert response.status == 200
%{pid: pid, stream: stream, opts: opts} = response.body
assert opts[:body_as] == :chunks
assert is_pid(pid)
assert is_reference(stream)
assert read_body(pid, stream) |> byte_size() == 16
refute Process.alive?(pid)
end
test "read response body in stream" do
request = %Env{
method: :get,
url: "#{@http}/stream-bytes/10"
}
assert {:ok, %Env{} = response} = call(request, body_as: :stream)
assert response.status == 200
assert is_function(response.body)
assert Enum.to_list(response.body) |> List.to_string() |> byte_size() == 16
end
test "read response body in stream with opened connection without closing connection" do
uri = URI.parse(@http)
{:ok, conn} = :gun.open(to_charlist(uri.host), uri.port)
request = %Env{
method: :get,
url: "#{@http}/stream-bytes/10"
}
assert {:ok, %Env{} = response} =
call(request, body_as: :stream, conn: conn, close_conn: false)
assert response.status == 200
assert is_function(response.body)
assert Enum.to_list(response.body) |> List.to_string() |> byte_size() == 16
assert Process.alive?(conn)
- :ok = :gun.close(conn)
+ :ok = Gun.close(conn)
refute Process.alive?(conn)
end
test "read response body in stream with opened connection with closing connection" do
uri = URI.parse(@http)
{:ok, conn} = :gun.open(to_charlist(uri.host), uri.port)
request = %Env{
method: :get,
url: "#{@http}/stream-bytes/10"
}
assert {:ok, %Env{} = response} = call(request, body_as: :stream, conn: conn)
assert response.status == 200
assert is_function(response.body)
assert Enum.to_list(response.body) |> List.to_string() |> byte_size() == 16
refute Process.alive?(conn)
end
defp read_body(pid, stream, acc \\ "") do
case Tesla.Adapter.Gun.read_chunk(pid, stream, timeout: 1_000) do
{:fin, body} ->
- :ok = :gun.close(pid)
+ :ok = Gun.close(pid)
acc <> body
{:nofin, part} ->
read_body(pid, stream, acc <> part)
end
end
end

File Metadata

Mime Type
text/x-diff
Expires
Thu, Nov 28, 8:18 AM (1 d, 19 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40984
Default Alt Text
(3 KB)

Event Timeline