Skip to content

Commit

Permalink
Additional tests for predicates
Browse files Browse the repository at this point in the history
  • Loading branch information
akoutmos committed Apr 12, 2020
1 parent 0ea17c7 commit 6e4e12c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/predicates/request_path_in_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
defmodule Unplug.Predicates.RequestPathInTest do
use ExUnit.Case, async: true
use Plug.Test

test "should return true if the expected value is in the request path list" do
conn = conn(:get, "/healthcheck")

assert Unplug.Predicates.RequestPathIn.call(conn, ["/metrics", "/healthcheck"])
end

test "should return false if the expected value is not in the request path list" do
conn = conn(:get, "/users")

refute Unplug.Predicates.RequestPathIn.call(conn, ["/metrics", "/healthcheck"])
end

test "should return true if the expected value is in the request path regex list" do
conn = conn(:get, "/healthcheck")

assert Unplug.Predicates.RequestPathIn.call(conn, ["/some_other_path", ~r/metrics/, ~r/healthcheck/])
end

test "should return false if the expected value does not match the request path regex" do
conn = conn(:get, "/users")

refute Unplug.Predicates.RequestPathIn.call(conn, ["/some_other_path", ~r/metrics/, ~r/healthcheck/])
end
end
28 changes: 28 additions & 0 deletions test/predicates/request_path_not_in_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
defmodule Unplug.Predicates.RequestPathNotInTest do
use ExUnit.Case, async: true
use Plug.Test

test "should return false if the expected value is in the request path list" do
conn = conn(:get, "/healthcheck")

refute Unplug.Predicates.RequestPathNotIn.call(conn, ["/metrics", "/healthcheck"])
end

test "should return true if the expected value is not in the request path list" do
conn = conn(:get, "/users")

assert Unplug.Predicates.RequestPathNotIn.call(conn, ["/metrics", "/healthcheck"])
end

test "should return false if the expected value is in the request path regex list" do
conn = conn(:get, "/healthcheck")

refute Unplug.Predicates.RequestPathNotIn.call(conn, ["/some_other_path", ~r/metrics/, ~r/healthcheck/])
end

test "should return true if the expected value does not match the request path regex" do
conn = conn(:get, "/users")

assert Unplug.Predicates.RequestPathNotIn.call(conn, ["/some_other_path", ~r/metrics/, ~r/healthcheck/])
end
end

0 comments on commit 6e4e12c

Please sign in to comment.