Skip to content

Commit 0b8c71a

Browse files
paulanthonywilsonedgurgel
authored andcommitted
fix test failures due to map key ordering
1 parent 24a3908 commit 0b8c71a

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

test/httpoison_base_test.exs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,32 @@ defmodule HTTPoisonBaseTest do
106106
end
107107

108108
test "request body using params example" do
109-
expect(:hackney, :request, fn :get, "http://localhost?foo=bar&key=fizz", [], "", [] ->
109+
expected_query = %{"foo" => "bar", "key" => "fizz"}
110+
111+
expect(:hackney, :request, fn :get, "http://localhost?" <> query, [], "", [] ->
112+
assert expected_query == URI.decode_query(query)
110113
{:ok, 200, "headers", :client}
111114
end)
112115

113116
expect(:hackney, :body, fn _, _ -> {:ok, "response"} end)
114117

115-
assert ExampleParamsOptions.get!("localhost", [], params: %{foo: "bar"}) ==
116-
%HTTPoison.Response{
117-
status_code: 200,
118-
headers: "headers",
119-
body: "response",
120-
request_url: "http://localhost?foo=bar&key=fizz",
121-
request: %HTTPoison.Request{
122-
body: "",
123-
headers: [],
124-
method: :get,
125-
options: [params: %{foo: "bar", key: "fizz"}],
126-
params: %{foo: "bar", key: "fizz"},
127-
url: "http://localhost?foo=bar&key=fizz"
128-
}
118+
assert %HTTPoison.Response{
119+
status_code: 200,
120+
headers: "headers",
121+
body: "response",
122+
request_url: "http://localhost?" <> request_url_query,
123+
request: %HTTPoison.Request{
124+
body: "",
125+
headers: [],
126+
method: :get,
127+
options: [params: %{foo: "bar", key: "fizz"}],
128+
params: %{foo: "bar", key: "fizz"},
129+
url: "http://localhost?" <> url_query
129130
}
131+
} = ExampleParamsOptions.get!("localhost", [], params: %{foo: "bar"})
132+
133+
assert expected_query == URI.decode_query(request_url_query)
134+
assert expected_query == URI.decode_query(url_query)
130135
end
131136

132137
test "get!/1 raises error tuple" do

test/httpoison_test.exs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ defmodule HTTPoisonTest do
1919
assert args["baz"] == "bong"
2020
assert args |> Map.keys() |> length == 2
2121

22-
assert Request.to_curl(response.request) ==
23-
{:ok, "curl -X GET http://localhost:4002/get?baz=bong&foo=bar"}
22+
assert {:ok, "curl -X GET http://localhost:4002/get?" <> query} =
23+
Request.to_curl(response.request)
24+
25+
assert %{"baz" => "bong", "foo" => "bar"} == URI.decode_query(query)
2426
end)
2527
end
2628

@@ -53,7 +55,7 @@ defmodule HTTPoisonTest do
5355
end
5456

5557
test "post charlist body" do
56-
assert_response(HTTPoison.post("localhost:4002/post", 'test'), fn response ->
58+
assert_response(HTTPoison.post("localhost:4002/post", ~c"test"), fn response ->
5759
assert Request.to_curl(response.request) == {:ok, "curl -X POST http://localhost:4002/post"}
5860
end)
5961
end
@@ -233,7 +235,7 @@ defmodule HTTPoisonTest do
233235
end
234236

235237
test "char list URL" do
236-
assert_response(HTTPoison.head('localhost:4002/get'), fn response ->
238+
assert_response(HTTPoison.head(~c"localhost:4002/get"), fn response ->
237239
assert Request.to_curl(response.request) ==
238240
{:ok, "curl -X HEAD http://localhost:4002/get"}
239241
end)

0 commit comments

Comments
 (0)