Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Plug.Adapters.Test.Conn tests #1235

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions test/plug/adapters/test/conn_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ defmodule Plug.Adapters.Test.ConnTest do
assert conn.query_params == %{"foo" => "bar"}
assert conn.params == %{"foo" => "bar", "biz" => "baz"}

conn = conn(:post, "/", %{foo: &length/1})
assert %{"foo" => value} = conn.body_params
assert is_function(value)
assert conn.query_string == ""
assert conn.query_params == %{}
assert conn.params == %{"foo" => &length/1}

conn = conn(:post, "/", %{foo: %{__struct__: :mod}})
assert %{"foo" => value} = conn.body_params
assert is_struct(value)
assert conn.query_string == ""
assert conn.query_params == %{}
assert conn.params == %{"foo" => %{__struct__: :mod}}

conn = conn(:post, "/", %{})
assert conn.body_params == %{}
assert conn.query_string == ""
Expand Down Expand Up @@ -158,9 +172,24 @@ defmodule Plug.Adapters.Test.ConnTest do
assert child_conn.port == 4200
end

test "conn/4 writes message to stderr when URI path does not start with forward slash" do
assert ExUnit.CaptureIO.capture_io(:stderr, fn ->
Plug.Adapters.Test.Conn.conn(%Plug.Conn{}, :get, "foo", [])
end) =~
~s(the URI path used in plug tests must start with "/", got: "foo")
end

test "use custom peer data" do
peer_data = %{address: {127, 0, 0, 1}, port: 111_317}
conn = conn(:get, "/") |> put_peer_data(peer_data)
assert peer_data == Plug.Conn.get_peer_data(conn)
end

test "push/3 sends message including path and headers" do
ref = make_ref()

Plug.Adapters.Test.Conn.push(%{owner: self(), ref: ref}, "/", [])

assert_receive {^ref, :push, {"/", []}}
end
end