Page MenuHomePhorge

No OneTemporary

Size
5 KB
Referenced Files
None
Subscribers
None
diff --git a/test/tesla/adapter/hackney_test.exs b/test/tesla/adapter/hackney_test.exs
index f95e859..8866897 100644
--- a/test/tesla/adapter/hackney_test.exs
+++ b/test/tesla/adapter/hackney_test.exs
@@ -1,12 +1,13 @@
defmodule HackneyTest do
use ExUnit.Case
use Tesla.Adapter.TestCase.Basic, adapter: :hackney
use Tesla.Adapter.TestCase.StreamRequestBody, adapter: :hackney
+ use Tesla.Adapter.TestCase.SSL, adapter: :hackney
setup do
case Application.ensure_started(:hackney) do
{:error, _} -> :hackney.start
:ok -> :ok
end
end
end
diff --git a/test/tesla/adapter/httpc_test.exs b/test/tesla/adapter/httpc_test.exs
index 98278ee..f1dd9e6 100644
--- a/test/tesla/adapter/httpc_test.exs
+++ b/test/tesla/adapter/httpc_test.exs
@@ -1,4 +1,5 @@
defmodule HttpcTest do
use ExUnit.Case
use Tesla.Adapter.TestCase.Basic, adapter: :httpc
+ use Tesla.Adapter.TestCase.SSL, adapter: :httpc
end
diff --git a/test/tesla/adapter/ibrowse_test.exs b/test/tesla/adapter/ibrowse_test.exs
index 86f207b..a663749 100644
--- a/test/tesla/adapter/ibrowse_test.exs
+++ b/test/tesla/adapter/ibrowse_test.exs
@@ -1,9 +1,10 @@
defmodule IbrowseTest do
use ExUnit.Case
use Tesla.Adapter.TestCase.Basic, adapter: :ibrowse
+ use Tesla.Adapter.TestCase.SSL, adapter: :ibrowse
setup do
Application.ensure_started(:ibrowse)
:ok
end
end
diff --git a/test/tesla/adapter/test_case.ex b/test/tesla/adapter/test_case.ex
index 9b651c1..99455d9 100644
--- a/test/tesla/adapter/test_case.ex
+++ b/test/tesla/adapter/test_case.ex
@@ -1,99 +1,122 @@
defmodule Tesla.Adapter.TestCase do
- @httpbin_url "http://localhost:#{Application.get_env(:httparrot, :http_port)}"
+ @http_url "http://localhost:#{Application.get_env(:httparrot, :http_port)}"
+ @https_url "https://httpbin.org"
- def httpbin_url, do: @httpbin_url
+ def http_url, do: @http_url
+ def https_url, do: @https_url
end
defmodule Tesla.Adapter.TestCase.Basic do
defmacro __using__([adapter: adapter]) do
quote do
defmodule B.Client do
use Tesla
adapter unquote(adapter)
end
- import Tesla.Adapter.TestCase, only: [httpbin_url: 0]
+ import Tesla.Adapter.TestCase, only: [http_url: 0]
require Tesla
setup do
{adapter, _} = B.Client.__adapter__
{:ok, adapter: adapter}
end
test "basic head request" do
- response = B.Client.head("#{httpbin_url}/ip")
+ response = B.Client.head("#{http_url}/ip")
assert response.status == 200
end
test "basic get request" do
- response = B.Client.get("#{httpbin_url}/ip")
+ response = B.Client.get("#{http_url}/ip")
assert response.status == 200
end
test "basic post request" do
- response = B.Client.post("#{httpbin_url}/post", "some-post-data", headers: %{"Content-Type" => "text/plain"})
+ response = B.Client.post("#{http_url}/post", "some-post-data", headers: %{"Content-Type" => "text/plain"})
assert response.status == 200
assert response.headers["content-type"] == "application/json"
assert Regex.match?(~r/some-post-data/, response.body)
end
test "passing query params" do
client = Tesla.build_client([{Tesla.Middleware.JSON, nil}])
- response = client |> B.Client.get("#{httpbin_url}/get", query: [
+ response = client |> B.Client.get("#{http_url}/get", query: [
page: 1, sort: "desc",
status: ["a", "b", "c"],
user: [name: "Jon", age: 20]
])
args = response.body["args"]
assert args["page"] == "1"
assert args["sort"] == "desc"
assert args["status[]"] == ["a", "b", "c"]
assert args["user[name]"] == "Jon"
assert args["user[age]"] == "20"
end
test "error: normalized connection refused error", %{adapter: adapter} do
assert {:error, :econnrefused} == adapter.call(%Tesla.Env{url: "http://localhost:1234"}, [])
end
test "error: connection refused" do
assert_raise Tesla.Error, fn ->
response = B.Client.get("http://localhost:1234")
end
end
end
end
end
defmodule Tesla.Adapter.TestCase.StreamRequestBody do
defmacro __using__([adapter: adapter]) do
quote do
defmodule S.Client do
use Tesla
adapter unquote(adapter)
end
- import Tesla.Adapter.TestCase, only: [httpbin_url: 0]
+ import Tesla.Adapter.TestCase, only: [http_url: 0]
test "stream request body: Stream.map" do
body = (1..5) |> Stream.map(&to_string/1)
- response = S.Client.post("#{httpbin_url}/post", body, headers: %{"Content-Type" => "text/plain"})
+ response = S.Client.post("#{http_url}/post", body, headers: %{"Content-Type" => "text/plain"})
assert response.status == 200
assert Regex.match?(~r/12345/, to_string(response.body))
end
test "stream request body: Stream.unfold" do
body = Stream.unfold(5, fn 0 -> nil; n -> {n,n-1} end)
|> Stream.map(&to_string/1)
- response = S.Client.post("#{httpbin_url}/post", body, headers: %{"Content-Type" => "text/plain"})
+ response = S.Client.post("#{http_url}/post", body, headers: %{"Content-Type" => "text/plain"})
assert response.status == 200
assert Regex.match?(~r/54321/, to_string(response.body))
end
end
end
end
+
+defmodule Tesla.Adapter.TestCase.SSL do
+ defmacro __using__([adapter: adapter]) do
+ quote do
+ defmodule SSL.Client do
+ use Tesla
+
+ adapter unquote(adapter)
+ end
+
+ import Tesla.Adapter.TestCase, only: [https_url: 0]
+
+ describe "SSL" do
+ test "basic get request" do
+ response = SSL.Client.get("#{https_url}/ip")
+ assert response.status == 200
+ end
+ end
+ end
+ end
+end

File Metadata

Mime Type
text/x-diff
Expires
Tue, Jun 24, 1:33 PM (1 d, 20 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
234883
Default Alt Text
(5 KB)

Event Timeline