Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmach committed Dec 9, 2024
1 parent 48f0232 commit 7ec3045
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions test/req/steps_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,34 +1006,36 @@ defmodule Req.StepsTest do

{resp, log} =
ExUnit.CaptureLog.with_log(fn ->
Req.get!("", plug: plug)
Req.get!(plug: plug)
end)

assert resp.body |> :zlib.uncompress() |> Jason.decode!() == %{"a" => 1}
assert log =~ ~s|algorithm \"deflate\" is not supported|
end

describe "redirect" do
test "ignore when :redirect is false", c do
Bypass.expect(c.bypass, "GET", "/redirect", fn conn ->
redirect(conn, 302, c.url <> "/ok")
end)
test "ignore when :redirect is false" do
%{url: url} =
start_http_server(fn conn ->
redirect(conn, 302, "/ok")
end)

assert Req.get!(c.url <> "/redirect", redirect: false).status == 302
assert Req.get!("#{url}/redirect", redirect: false).status == 302
end

test "absolute", c do
Bypass.expect(c.bypass, "GET", "/redirect", fn conn ->
redirect(conn, 302, c.url <> "/ok")
end)
test "absolute" do
%{url: url} =
start_http_server(fn
conn when conn.request_path == "/redirect" ->
redirect(conn, 302, "http://localhost:#{conn.port}/ok")

Bypass.expect(c.bypass, "GET", "/ok", fn conn ->
Plug.Conn.send_resp(conn, 200, "ok")
end)
conn when conn.request_path == "/ok" ->
redirect(conn, 200, "/ok")
end)

assert ExUnit.CaptureLog.capture_log(fn ->
assert Req.get!(c.url <> "/redirect").status == 200
end) =~ "[debug] redirecting to #{c.url}/ok"
assert Req.get!("#{url}/redirect", retry: false).status == 200
end) =~ "[debug] redirecting to #{url}/ok"
end

test "relative", c do
Expand Down

0 comments on commit 7ec3045

Please sign in to comment.