Page MenuHomePhorge

No OneTemporary

Size
4 KB
Referenced Files
None
Subscribers
None
diff --git a/test/tesla/adapter/gun_test.exs b/test/tesla/adapter/gun_test.exs
index eba4770..a53cfa3 100644
--- a/test/tesla/adapter/gun_test.exs
+++ b/test/tesla/adapter/gun_test.exs
@@ -1,132 +1,155 @@
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",
+ url: "#{@http}/stream-bytes/100",
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)
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
+ test "error response" do
+ request = %Env{
+ method: :get,
+ url: "#{@http}/status/500"
+ }
+
+ assert {:ok, %Env{} = response} = call(request, timeout: 1_000)
+ assert response.status == 500
+ end
+
+ test "query without path" do
+ request = %Env{
+ method: :get,
+ url: "#{@http}",
+ query: [
+ param: "value"
+ ]
+ }
+
+ assert {:ok, %Env{} = response} = call(request, timeout: 1_000)
+ assert response.status == 400
+ 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)
acc <> body
{:nofin, part} ->
read_body(pid, stream, acc <> part)
end
end
end

File Metadata

Mime Type
text/x-diff
Expires
Thu, Nov 28, 6:38 AM (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40942
Default Alt Text
(4 KB)

Event Timeline