Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
edgurgel committed Jan 30, 2023
1 parent 0b476f8 commit 596fa03
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 57 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ jobs:
fail-fast: false
matrix:
include:
- otp: 23.0
elixir: 1.11.2
- otp: 25.1
elixir: 1.14.1
coverage: true
Expand Down
10 changes: 5 additions & 5 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use Mix.Config
import Config

if Mix.env() == :test do
if config_env() == :test do
config :httparrot,
http_port: 8080,
ssl: true,
https_port: 8433
https_port: 8433,
http_port: 4002,
ssl: true
end
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ defmodule HTTPoison.Mixfile do
{:mimic, "~> 0.1", only: :test},
{:jason, "~> 1.2", only: :test},
{:httparrot, "~> 1.2", only: :test},
{:cowboy, "~> 2.8", only: :test, override: true},
{:earmark, "~> 1.0", only: :dev},
{:ex_doc, "~> 0.18", only: :dev},
{:dialyxir, "~> 1.0.0-rc.3", only: [:dev, :test], runtime: false}
Expand Down
6 changes: 3 additions & 3 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
%{
"certifi": {:hex, :certifi, "2.5.3", "70bdd7e7188c804f3a30ee0e7c99655bc35d8ac41c23e12325f36ab449b70651", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm", "ed516acb3929b101208a9d700062d520f3953da3b6b918d866106ffa980e1c10"},
"con_cache": {:hex, :con_cache, "0.14.0", "863acb90fa08017be3129074993af944cf7a4b6c3ee7c06c5cd0ed6b94fbc223", [:mix], [], "hexpm", "50887a8949377d0b707a3c6653b7610de06074751b52d0f267f52135f391aece"},
"cowboy": {:hex, :cowboy, "2.8.0", "f3dc62e35797ecd9ac1b50db74611193c29815401e53bac9a5c0577bd7bc667d", [:rebar3], [{:cowlib, "~> 2.9.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "4643e4fba74ac96d4d152c75803de6fad0b3fa5df354c71afdd6cbeeb15fac8a"},
"cowlib": {:hex, :cowlib, "2.9.1", "61a6c7c50cf07fdd24b2f45b89500bb93b6686579b069a89f88cb211e1125c78", [:rebar3], [], "hexpm", "e4175dc240a70d996156160891e1c62238ede1729e45740bdd38064dad476170"},
"cowboy": {:hex, :cowboy, "2.9.0", "865dd8b6607e14cf03282e10e934023a1bd8be6f6bacf921a7e2a96d800cd452", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "2c729f934b4e1aa149aff882f57c6372c15399a20d54f65c8d67bef583021bde"},
"cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"},
"dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"},
"earmark": {:hex, :earmark, "1.4.18", "618c4ff1563450d1832b7fb41dc6755e470f91a6fd4c70f350a58b14f64a7db8", [:mix], [{:earmark_parser, ">= 1.4.17", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "57ac3b6da3958ed09c669a9b159e86377fcccda56bacde8a209fa4dcdef52560"},
"earmark_parser": {:hex, :earmark_parser, "1.4.17", "6f3c7e94170377ba45241d394389e800fb15adc5de51d0a3cd52ae766aafd63f", [:mix], [], "hexpm", "f93ac89c9feca61c165b264b5837bf82344d13bebc634cd575cb711e2e342023"},
Expand All @@ -22,7 +22,7 @@
"mimic": {:hex, :mimic, "0.3.0", "584dfd5ac2ce3347f56b0de3b7906554e2f6020007efed37e721b968f27ebbc0", [:mix], [], "hexpm", "6e817cbd79bca8c70b90b1e3268fb54bbd0c89387e2143236f0233bf935cc5a1"},
"nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},
"parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm", "17ef63abde837ad30680ea7f857dd9e7ced9476cdd7b0394432af4bfc241b960"},
"ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm", "451d8527787df716d99dc36162fca05934915db0b6141bbdac2ea8d3c7afc7d7"},
"ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"},
}
94 changes: 47 additions & 47 deletions test/httpoison_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ defmodule HTTPoisonTest do
alias HTTPoison.Request

test "get" do
assert_response(HTTPoison.get("localhost:8080/deny"), fn response ->
assert_response(HTTPoison.get("localhost:4002/deny"), fn response ->
assert :erlang.size(response.body) == 197
end)
end

test "get with params" do
resp = HTTPoison.get("localhost:8080/get", [], params: %{foo: "bar", baz: "bong"})
resp = HTTPoison.get("localhost:4002/get", [], params: %{foo: "bar", baz: "bong"})

assert_response(resp, fn response ->
args = Jason.decode!(response.body)["args"]
Expand All @@ -20,14 +20,14 @@ defmodule HTTPoisonTest do
assert args |> Map.keys() |> length == 2

assert Request.to_curl(response.request) ==
{:ok, "curl -X GET http://localhost:8080/get?baz=bong&foo=bar"}
{:ok, "curl -X GET http://localhost:4002/get?baz=bong&foo=bar"}
end)
end

test "get with params in url and options" do
resp =
HTTPoison.get(
"localhost:8080/get?bar=zing&foo=first",
"localhost:4002/get?bar=zing&foo=first",
[],
params: [{"foo", "second"}, {"baz", "bong"}]
)
Expand All @@ -41,106 +41,106 @@ defmodule HTTPoisonTest do

assert Request.to_curl(response.request) ==
{:ok,
"curl -X GET http://localhost:8080/get?bar=zing&foo=first&foo=second&baz=bong"}
"curl -X GET http://localhost:4002/get?bar=zing&foo=first&foo=second&baz=bong"}
end)
end

test "head" do
assert_response(HTTPoison.head("localhost:8080/get"), fn response ->
assert_response(HTTPoison.head("localhost:4002/get"), fn response ->
assert response.body == ""
assert Request.to_curl(response.request) == {:ok, "curl -X HEAD http://localhost:8080/get"}
assert Request.to_curl(response.request) == {:ok, "curl -X HEAD http://localhost:4002/get"}
end)
end

test "post charlist body" do
assert_response(HTTPoison.post("localhost:8080/post", 'test'), fn response ->
assert Request.to_curl(response.request) == {:ok, "curl -X POST http://localhost:8080/post"}
assert_response(HTTPoison.post("localhost:4002/post", 'test'), fn response ->
assert Request.to_curl(response.request) == {:ok, "curl -X POST http://localhost:4002/post"}
end)
end

test "post binary body" do
{:ok, file} = File.read(fixture_path("image.png"))

assert_response(HTTPoison.post("localhost:8080/post", file), fn response ->
assert_response(HTTPoison.post("localhost:4002/post", file), fn response ->
assert Request.to_curl(response.request) ==
{:ok, "curl -X POST -d '#{file}' http://localhost:8080/post"}
{:ok, "curl -X POST -d '#{file}' http://localhost:4002/post"}
end)
end

test "post form data" do
assert_response(
HTTPoison.post("localhost:8080/post", {:form, [key: "value"]}, %{
HTTPoison.post("localhost:4002/post", {:form, [key: "value"]}, %{
"Content-type" => "application/x-www-form-urlencoded"
}),
fn response ->
Regex.match?(~r/"key".*"value"/, response.body)

assert Request.to_curl(response.request) ==
{:ok,
"curl -X POST -H 'Content-type: application/x-www-form-urlencoded' -F 'key=value' http://localhost:8080/post"}
"curl -X POST -H 'Content-type: application/x-www-form-urlencoded' -F 'key=value' http://localhost:4002/post"}
end
)
end

test "put" do
assert_response(HTTPoison.put("localhost:8080/put", "test"), fn response ->
assert_response(HTTPoison.put("localhost:4002/put", "test"), fn response ->
assert Request.to_curl(response.request) ==
{:ok, "curl -X PUT -d 'test' http://localhost:8080/put"}
{:ok, "curl -X PUT -d 'test' http://localhost:4002/put"}
end)
end

test "put without body" do
assert_response(HTTPoison.put("localhost:8080/put"), fn response ->
assert_response(HTTPoison.put("localhost:4002/put"), fn response ->
assert Request.to_curl(response.request) ==
{:ok, "curl -X PUT http://localhost:8080/put"}
{:ok, "curl -X PUT http://localhost:4002/put"}
end)
end

test "patch" do
assert_response(HTTPoison.patch("localhost:8080/patch", "test"), fn response ->
assert_response(HTTPoison.patch("localhost:4002/patch", "test"), fn response ->
assert Request.to_curl(response.request) ==
{:ok, "curl -X PATCH -d 'test' http://localhost:8080/patch"}
{:ok, "curl -X PATCH -d 'test' http://localhost:4002/patch"}
end)
end

test "delete" do
assert_response(HTTPoison.delete("localhost:8080/delete"), fn response ->
assert_response(HTTPoison.delete("localhost:4002/delete"), fn response ->
assert Request.to_curl(response.request) ==
{:ok, "curl -X DELETE http://localhost:8080/delete"}
{:ok, "curl -X DELETE http://localhost:4002/delete"}
end)
end

test "options" do
assert_response(HTTPoison.options("localhost:8080/get"), fn response ->
assert_response(HTTPoison.options("localhost:4002/get"), fn response ->
assert get_header(response.headers, "content-length") == "0"
assert is_binary(get_header(response.headers, "allow"))

assert Request.to_curl(response.request) ==
{:ok, "curl -X OPTIONS http://localhost:8080/get"}
{:ok, "curl -X OPTIONS http://localhost:4002/get"}
end)
end

test "option follow redirect absolute url" do
assert_response(
HTTPoison.get(
"http://localhost:8080/redirect-to?url=http%3A%2F%2Flocalhost:8080%2Fget",
"http://localhost:4002/redirect-to?url=http%3A%2F%2Flocalhost:4002%2Fget",
[],
follow_redirect: true
),
fn response ->
assert Request.to_curl(response.request) ==
{:ok,
"curl -L --max-redirs 5 -X GET http://localhost:8080/redirect-to?url=http%3A%2F%2Flocalhost:8080%2Fget"}
"curl -L --max-redirs 5 -X GET http://localhost:4002/redirect-to?url=http%3A%2F%2Flocalhost:4002%2Fget"}
end
)
end

test "option follow redirect relative url" do
assert_response(
HTTPoison.get("http://localhost:8080/relative-redirect/1", [], follow_redirect: true),
HTTPoison.get("http://localhost:4002/relative-redirect/1", [], follow_redirect: true),
fn response ->
assert Request.to_curl(response.request) ==
{:ok, "curl -L --max-redirs 5 -X GET http://localhost:8080/relative-redirect/1"}
{:ok, "curl -L --max-redirs 5 -X GET http://localhost:4002/relative-redirect/1"}
end
)
end
Expand All @@ -149,14 +149,14 @@ defmodule HTTPoisonTest do
hackney = [basic_auth: {"user", "pass"}]

assert_response(
HTTPoison.get("http://localhost:8080/basic-auth/user/pass", [], hackney: hackney)
HTTPoison.get("http://localhost:4002/basic-auth/user/pass", [], hackney: hackney)
)
end

test "explicit http scheme" do
assert_response(HTTPoison.head("http://localhost:8080/get"), fn response ->
assert_response(HTTPoison.head("http://localhost:4002/get"), fn response ->
assert Request.to_curl(response.request) ==
{:ok, "curl -X HEAD http://localhost:8080/get"}
{:ok, "curl -X HEAD http://localhost:4002/get"}
end)
end

Expand All @@ -181,44 +181,44 @@ defmodule HTTPoisonTest do
end

test "char list URL" do
assert_response(HTTPoison.head('localhost:8080/get'), fn response ->
assert_response(HTTPoison.head('localhost:4002/get'), fn response ->
assert Request.to_curl(response.request) ==
{:ok, "curl -X HEAD http://localhost:8080/get"}
{:ok, "curl -X HEAD http://localhost:4002/get"}
end)
end

test "request headers as a map" do
map_header = %{"X-Header" => "X-Value"}
assert response = HTTPoison.get!("localhost:8080/get", map_header)
assert response = HTTPoison.get!("localhost:4002/get", map_header)
assert response.body =~ "X-Value"

assert Request.to_curl(response.request) ==
{:ok, "curl -X GET -H 'X-Header: X-Value' http://localhost:8080/get"}
{:ok, "curl -X GET -H 'X-Header: X-Value' http://localhost:4002/get"}
end

test "cached request" do
if_modified = %{"If-Modified-Since" => "Tue, 11 Dec 2012 10:10:24 GMT"}
response = HTTPoison.get!("localhost:8080/cache", if_modified)
response = HTTPoison.get!("localhost:4002/cache", if_modified)
assert %HTTPoison.Response{status_code: 304, body: ""} = response

assert Request.to_curl(response.request) ==
{:ok,
"curl -X GET -H 'If-Modified-Since: Tue, 11 Dec 2012 10:10:24 GMT' http://localhost:8080/cache"}
"curl -X GET -H 'If-Modified-Since: Tue, 11 Dec 2012 10:10:24 GMT' http://localhost:4002/cache"}
end

test "send cookies" do
response = HTTPoison.get!("localhost:8080/cookies", %{}, hackney: [cookie: ["foo=1; bar=2"]])
response = HTTPoison.get!("localhost:4002/cookies", %{}, hackney: [cookie: ["foo=1; bar=2"]])
assert Jason.decode!(response.body) == %{"cookies" => %{"foo" => "1", "bar" => "2"}}
end

test "receive cookies" do
response = HTTPoison.get!("localhost:8080/cookies/set?foo=1&bar=2")
response = HTTPoison.get!("localhost:4002/cookies/set?foo=1&bar=2")
has_foo = Enum.member?(response.headers, {"set-cookie", "foo=1; Version=1; Path=/"})
has_bar = Enum.member?(response.headers, {"set-cookie", "bar=2; Version=1; Path=/"})
assert has_foo and has_bar

assert Request.to_curl(response.request) ==
{:ok, "curl -X GET http://localhost:8080/cookies/set?foo=1&bar=2"}
{:ok, "curl -X GET http://localhost:4002/cookies/set?foo=1&bar=2"}
end

test "exception" do
Expand All @@ -231,7 +231,7 @@ defmodule HTTPoisonTest do

test "asynchronous request" do
{:ok, %HTTPoison.AsyncResponse{id: id}} =
HTTPoison.get("localhost:8080/get", [], stream_to: self())
HTTPoison.get("localhost:4002/get", [], stream_to: self())

assert_receive %HTTPoison.AsyncStatus{id: ^id, code: 200}, 1_000
assert_receive %HTTPoison.AsyncHeaders{id: ^id, headers: headers}, 1_000
Expand All @@ -242,7 +242,7 @@ defmodule HTTPoisonTest do

test "asynchronous request with explicit streaming using [async: :once]" do
{:ok, resp = %HTTPoison.AsyncResponse{id: id}} =
HTTPoison.get("localhost:8080/get", [], stream_to: self(), async: :once)
HTTPoison.get("localhost:4002/get", [], stream_to: self(), async: :once)

assert_receive %HTTPoison.AsyncStatus{id: ^id, code: 200}, 100

Expand All @@ -264,21 +264,21 @@ defmodule HTTPoisonTest do
test "asynchronous redirected get request" do
{:ok, %HTTPoison.AsyncResponse{id: id}} =
HTTPoison.get(
"localhost:8080/redirect/2",
"localhost:4002/redirect/2",
[],
stream_to: self(),
hackney: [follow_redirect: true]
)

assert_receive %HTTPoison.AsyncRedirect{id: ^id, to: to, headers: headers}, 1_000
assert to == "http://localhost:8080/redirect/1"
assert to == "http://localhost:4002/redirect/1"
assert is_list(headers)
end

test "multipart upload" do
response =
HTTPoison.post(
"localhost:8080/post",
"localhost:4002/post",
{:multipart, [{:file, "test/test_helper.exs"}, {"name", "value"}]}
)

Expand All @@ -289,14 +289,14 @@ defmodule HTTPoisonTest do
expected = %{"some" => "bytes"}
enumerable = Jason.encode!(expected) |> String.split("")
headers = %{"Content-type" => "application/json"}
response = HTTPoison.post("localhost:8080/post", {:stream, enumerable}, headers)
response = HTTPoison.post("localhost:4002/post", {:stream, enumerable}, headers)

assert_response(response, fn response ->
assert Jason.decode!(response.body)["json"] == expected

assert Request.to_curl(response.request) ==
{:ok,
"curl -X POST -H 'Content-type: application/json' -d '{\"some\":\"bytes\"}' http://localhost:8080/post"}
"curl -X POST -H 'Content-type: application/json' -d '{\"some\":\"bytes\"}' http://localhost:4002/post"}
end)
end

Expand All @@ -312,7 +312,7 @@ defmodule HTTPoisonTest do
|> Kernel.*(buffer_size)
|> Kernel.trunc()

resp = HTTPoison.get("localhost:8080/stream/20", [], max_body_length: max_length)
resp = HTTPoison.get("localhost:4002/stream/20", [], max_body_length: max_length)

assert_response(resp, fn response ->
assert byte_size(response.body) <= expected_length
Expand Down

0 comments on commit 596fa03

Please sign in to comment.