aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2020-03-29 15:44:47 +0200
committerLoïc Hoguin <[email protected]>2020-03-29 15:44:47 +0200
commit70e43ec11213e2e8f43f0ec4e407ea3dc7120fe1 (patch)
tree180474c2329a1fc356a0b80aa78ab4a1868117af
parent6ad842a742915066d319f307a0f60cd8df15598b (diff)
downloadcowboy-70e43ec11213e2e8f43f0ec4e407ea3dc7120fe1.tar.gz
cowboy-70e43ec11213e2e8f43f0ec4e407ea3dc7120fe1.tar.bz2
cowboy-70e43ec11213e2e8f43f0ec4e407ea3dc7120fe1.zip
Add more router tests
-rw-r--r--src/cowboy_router.erl20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/cowboy_router.erl b/src/cowboy_router.erl
index 0eb4bdd..0b7fe41 100644
--- a/src/cowboy_router.erl
+++ b/src/cowboy_router.erl
@@ -372,6 +372,8 @@ list_match([E|Tail], [E|TailMatch], Binds) ->
%% unless V was already defined and E isn't identical to the previous value.
list_match([E|Tail], [V|TailMatch], Binds) when is_atom(V) ->
case Binds of
+ %% @todo This isn't right, the constraint must be applied FIRST
+ %% otherwise we can't check for example ints in both host/path.
#{V := E} ->
list_match(Tail, TailMatch, Binds);
#{V := _} ->
@@ -514,7 +516,9 @@ match_test_() ->
{<<"erlang.fr">>, '_',
{ok, match_erlang_ext, [], #{ext => <<"fr">>}}},
{<<"any">>, <<"/users/444/friends">>,
- {ok, match_users_friends, [], #{id => <<"444">>}}}
+ {ok, match_users_friends, [], #{id => <<"444">>}}},
+ {<<"any">>, <<"/users//friends">>,
+ {ok, match_users_friends, [], #{id => <<>>}}}
],
[{lists:flatten(io_lib:format("~p, ~p", [H, P])), fun() ->
{ok, Handler, Opts, Binds, undefined, undefined}
@@ -549,14 +553,20 @@ match_info_test_() ->
end} || {H, P, R} <- Tests].
match_constraints_test() ->
- Dispatch = [{'_', [],
+ Dispatch0 = [{'_', [],
[{[<<"path">>, value], [{value, int}], match, []}]}],
- {ok, _, [], #{value := 123}, _, _} = match(Dispatch,
+ {ok, _, [], #{value := 123}, _, _} = match(Dispatch0,
<<"ninenines.eu">>, <<"/path/123">>),
- {ok, _, [], #{value := 123}, _, _} = match(Dispatch,
+ {ok, _, [], #{value := 123}, _, _} = match(Dispatch0,
<<"ninenines.eu">>, <<"/path/123/">>),
- {error, notfound, path} = match(Dispatch,
+ {error, notfound, path} = match(Dispatch0,
<<"ninenines.eu">>, <<"/path/NaN/">>),
+ Dispatch1 = [{'_', [],
+ [{[<<"path">>, value, <<"more">>], [{value, nonempty}], match, []}]}],
+ {ok, _, [], #{value := <<"something">>}, _, _} = match(Dispatch1,
+ <<"ninenines.eu">>, <<"/path/something/more">>),
+ {error, notfound, path} = match(Dispatch1,
+ <<"ninenines.eu">>, <<"/path//more">>),
Dispatch2 = [{'_', [], [{[<<"path">>, username],
[{username, fun(_, Value) ->
case cowboy_bstr:to_lower(Value) of