Skip to content

Commit

Permalink
test: match, to: functional_plug
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmcguin committed Sep 5, 2024
1 parent 7c408c9 commit aed4519
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/plug/router_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,18 @@ defmodule Plug.RouterTest do
forward "/plug/init_opts", to: plug, init_opts: opts, private: %{baz: :qux}

forward "/plug/forward_local", to: :forward_local
match "/plug/match_local", to: :match_local
forward "/plug/forward_local_opts", to: :forward_local, init_opts: opts, private: %{baz: :qux}
match "/plug/match_local_opts", to: :match_local, init_opts: opts, private: %{baz: :qux}

def forward_local(conn, opts) do
resp(conn, 200, "#{inspect(opts)}")
end

def match_local(conn, opts) do
resp(conn, 200, "#{inspect(opts)}")
end

match _ do
resp(conn, 404, "oops")
end
Expand Down Expand Up @@ -586,12 +592,23 @@ defmodule Plug.RouterTest do
assert conn.resp_body == "[]"
end

test "matches to a function plug" do
conn = call(Sample, conn(:get, "/plug/match_local"))
assert conn.resp_body == "[]"
end

test "forwards to a function plug with options" do
conn = call(Sample, conn(:get, "/plug/forward_local_opts"))
assert conn.private[:baz] == :qux
assert conn.resp_body == ":hello"
end

test "matches to a function plug with options" do
conn = call(Sample, conn(:get, "/plug/match_local_opts"))
assert conn.private[:baz] == :qux
assert conn.resp_body == ":hello"
end

test "emit start and stop event when router dispatches" do
start_router_id = {:start, :rand.uniform(100)}
stop_router_id = {:stop, :rand.uniform(100)}
Expand Down

0 comments on commit aed4519

Please # to comment.