Skip to content

Commit

Permalink
attempt to fix tests on OTP 22
Browse files Browse the repository at this point in the history
  • Loading branch information
asakura committed Nov 17, 2023
1 parent 4a66d92 commit 57d6221
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/mixpanel/http/hackney.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ if Code.ensure_loaded?(:hackney) do
{:error, "Redirect not supported"}

{:error, reason} ->
{:error, to_string(reason)}
{:error, inspect(reason)}
end
end
end
Expand Down
6 changes: 4 additions & 2 deletions lib/mixpanel/http/httpc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ if Code.ensure_loaded?(:httpc) do

case do_request(
method,
url,
# Erlang 22 comparability layer: httpc wants a charlist as URL
# Remove it when OTP 22 support is dropped
String.to_charlist(url),
prepare_headers(headers),
content_type,
payload,
Expand All @@ -57,7 +59,7 @@ if Code.ensure_loaded?(:httpc) do
{:ok, status_code, format_headers(headers), to_string(body)}

{:error, reason} ->
{:error, to_string(reason)}
{:error, inspect(reason)}
end
end

Expand Down
11 changes: 6 additions & 5 deletions test/http_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ defmodule MixpanelTest.HTTPTest do

alias Mixpanel.HTTP.{Hackney, HTTPC, NoOp}

@base_url "https://localhost:40010"

setup_all do
child =
{
Expand All @@ -25,16 +27,15 @@ defmodule MixpanelTest.HTTPTest do

describe "NoOp adapter" do
test "get/3" do
response =
NoOp.get("https://localhost:40010/get_endpoint", [], insecure: true)
response = NoOp.get("#{@base_url}/get_endpoint", [], insecure: true)

assert response == {:ok, 200, [], "1"}
end

test "post/4" do
response =
NoOp.post(
"https://localhost:40010/post_endpoint",
"#{@base_url}/post_endpoint",
"body",
[
{"Content-Type", "application/x-www-form-urlencoded"}
Expand All @@ -49,7 +50,7 @@ defmodule MixpanelTest.HTTPTest do
describe "HTTP adapters" do
for adapter <- [Hackney, HTTPC] do
test "#{adapter}.get/3" do
case unquote(adapter).get("https://localhost:40010/get_endpoint", [], insecure: true) do
case unquote(adapter).get("#{@base_url}/get_endpoint", [], insecure: true) do
{:ok, 200, _headers, body} ->
assert Jason.decode!(body)
~> %{
Expand All @@ -71,7 +72,7 @@ defmodule MixpanelTest.HTTPTest do

test "#{adapter}.post/4" do
case unquote(adapter).post(
"https://localhost:40010/post_endpoint",
"#{@base_url}/post_endpoint",
"body",
[
{"Content-Type", "application/x-www-form-urlencoded"}
Expand Down

0 comments on commit 57d6221

Please sign in to comment.