0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-15 12:40:25 +00:00

Fix unit tests in cowboy_router following interface changes

This commit is contained in:
Loïc Hoguin 2017-06-28 18:57:04 +02:00
parent c221730371
commit 12b5e78aaa
No known key found for this signature in database
GPG key ID: 71366FF21851DF03

View file

@ -487,23 +487,23 @@ match_test_() ->
]} ]}
], ],
Tests = [ Tests = [
{<<"any">>, <<"/">>, {ok, match_any, [], []}}, {<<"any">>, <<"/">>, {ok, match_any, [], #{}}},
{<<"www.any.ninenines.eu">>, <<"/users/42/mails">>, {<<"www.any.ninenines.eu">>, <<"/users/42/mails">>,
{ok, match_any_subdomain_users, [], []}}, {ok, match_any_subdomain_users, [], #{}}},
{<<"www.ninenines.eu">>, <<"/users/42/mails">>, {<<"www.ninenines.eu">>, <<"/users/42/mails">>,
{ok, match_any, [], []}}, {ok, match_any, [], #{}}},
{<<"www.ninenines.eu">>, <<"/">>, {<<"www.ninenines.eu">>, <<"/">>,
{ok, match_any, [], []}}, {ok, match_any, [], #{}}},
{<<"www.any.ninenines.eu">>, <<"/not_users/42/mails">>, {<<"www.any.ninenines.eu">>, <<"/not_users/42/mails">>,
{error, notfound, path}}, {error, notfound, path}},
{<<"ninenines.eu">>, <<"/">>, {<<"ninenines.eu">>, <<"/">>,
{ok, match_extend, [], []}}, {ok, match_extend, [], #{}}},
{<<"ninenines.eu">>, <<"/users/42/friends">>, {<<"ninenines.eu">>, <<"/users/42/friends">>,
{ok, match_extend_users_friends, [], [{id, <<"42">>}]}}, {ok, match_extend_users_friends, [], #{id => <<"42">>}}},
{<<"erlang.fr">>, '_', {<<"erlang.fr">>, '_',
{ok, match_erlang_ext, [], [{ext, <<"fr">>}]}}, {ok, match_erlang_ext, [], #{ext => <<"fr">>}}},
{<<"any">>, <<"/users/444/friends">>, {<<"any">>, <<"/users/444/friends">>,
{ok, match_users_friends, [], [{id, <<"444">>}]}} {ok, match_users_friends, [], #{id => <<"444">>}}}
], ],
[{lists:flatten(io_lib:format("~p, ~p", [H, P])), fun() -> [{lists:flatten(io_lib:format("~p, ~p", [H, P])), fun() ->
{ok, Handler, Opts, Binds, undefined, undefined} {ok, Handler, Opts, Binds, undefined, undefined}
@ -525,21 +525,21 @@ match_info_test_() ->
], ],
Tests = [ Tests = [
{<<"ninenines.eu">>, <<"/">>, {<<"ninenines.eu">>, <<"/">>,
{ok, match_any, [], [], [], undefined}}, {ok, match_any, [], #{}, [], undefined}},
{<<"bugs.ninenines.eu">>, <<"/">>, {<<"bugs.ninenines.eu">>, <<"/">>,
{ok, match_any, [], [], [<<"bugs">>], undefined}}, {ok, match_any, [], #{}, [<<"bugs">>], undefined}},
{<<"cowboy.bugs.ninenines.eu">>, <<"/">>, {<<"cowboy.bugs.ninenines.eu">>, <<"/">>,
{ok, match_any, [], [], [<<"cowboy">>, <<"bugs">>], undefined}}, {ok, match_any, [], #{}, [<<"cowboy">>, <<"bugs">>], undefined}},
{<<"www.ninenines.eu">>, <<"/pathinfo/is/next">>, {<<"www.ninenines.eu">>, <<"/pathinfo/is/next">>,
{ok, match_path, [], [], undefined, []}}, {ok, match_path, [], #{}, undefined, []}},
{<<"www.ninenines.eu">>, <<"/pathinfo/is/next/path_info">>, {<<"www.ninenines.eu">>, <<"/pathinfo/is/next/path_info">>,
{ok, match_path, [], [], undefined, [<<"path_info">>]}}, {ok, match_path, [], #{}, undefined, [<<"path_info">>]}},
{<<"www.ninenines.eu">>, <<"/pathinfo/is/next/foo/bar">>, {<<"www.ninenines.eu">>, <<"/pathinfo/is/next/foo/bar">>,
{ok, match_path, [], [], undefined, [<<"foo">>, <<"bar">>]}}, {ok, match_path, [], #{}, undefined, [<<"foo">>, <<"bar">>]}},
% Cyrillic from a latin1 encoded file. % Cyrillic from a latin1 encoded file.
{<<209,129,208,176,208,185,209,130,46,209,128,209,132>>, {<<209,129,208,176,208,185,209,130,46,209,128,209,132>>,
<<47,208,191,209,131,209,130,209,140,47,208,180,208,190,208,188,208,190,208,185>>, <<47,208,191,209,131,209,130,209,140,47,208,180,208,190,208,188,208,190,208,185>>,
{ok, match_path, [], [], undefined, [<<208,180,208,190,208,188,208,190,208,185>>]}} {ok, match_path, [], #{}, undefined, [<<208,180,208,190,208,188,208,190,208,185>>]}}
], ],
[{lists:flatten(io_lib:format("~p, ~p", [H, P])), fun() -> [{lists:flatten(io_lib:format("~p, ~p", [H, P])), fun() ->
R = match(Dispatch, H, P) R = match(Dispatch, H, P)
@ -548,16 +548,20 @@ match_info_test_() ->
match_constraints_test() -> match_constraints_test() ->
Dispatch = [{'_', [], Dispatch = [{'_', [],
[{[<<"path">>, value], [{value, int}], match, []}]}], [{[<<"path">>, value], [{value, int}], match, []}]}],
{ok, _, [], [{value, 123}], _, _} = match(Dispatch, {ok, _, [], #{value := 123}, _, _} = match(Dispatch,
<<"ninenines.eu">>, <<"/path/123">>), <<"ninenines.eu">>, <<"/path/123">>),
{ok, _, [], [{value, 123}], _, _} = match(Dispatch, {ok, _, [], #{value := 123}, _, _} = match(Dispatch,
<<"ninenines.eu">>, <<"/path/123/">>), <<"ninenines.eu">>, <<"/path/123/">>),
{error, notfound, path} = match(Dispatch, {error, notfound, path} = match(Dispatch,
<<"ninenines.eu">>, <<"/path/NaN/">>), <<"ninenines.eu">>, <<"/path/NaN/">>),
Dispatch2 = [{'_', [], [{[<<"path">>, username], Dispatch2 = [{'_', [], [{[<<"path">>, username],
[{username, fun(Value) -> Value =:= cowboy_bstr:to_lower(Value) end}], [{username, fun(_, Value) ->
case cowboy_bstr:to_lower(Value) of
Value -> {ok, Value};
_ -> {error, not_lowercase}
end end}],
match, []}]}], match, []}]}],
{ok, _, [], [{username, <<"essen">>}], _, _} = match(Dispatch2, {ok, _, [], #{username := <<"essen">>}, _, _} = match(Dispatch2,
<<"ninenines.eu">>, <<"/path/essen">>), <<"ninenines.eu">>, <<"/path/essen">>),
{error, notfound, path} = match(Dispatch2, {error, notfound, path} = match(Dispatch2,
<<"ninenines.eu">>, <<"/path/ESSEN">>), <<"ninenines.eu">>, <<"/path/ESSEN">>),
@ -565,20 +569,20 @@ match_constraints_test() ->
match_same_bindings_test() -> match_same_bindings_test() ->
Dispatch = [{[same, same], [], [{'_', [], match, []}]}], Dispatch = [{[same, same], [], [{'_', [], match, []}]}],
{ok, _, [], [{same, <<"eu">>}], _, _} = match(Dispatch, {ok, _, [], #{same := <<"eu">>}, _, _} = match(Dispatch,
<<"eu.eu">>, <<"/">>), <<"eu.eu">>, <<"/">>),
{error, notfound, host} = match(Dispatch, {error, notfound, host} = match(Dispatch,
<<"ninenines.eu">>, <<"/">>), <<"ninenines.eu">>, <<"/">>),
Dispatch2 = [{[<<"eu">>, <<"ninenines">>, user], [], Dispatch2 = [{[<<"eu">>, <<"ninenines">>, user], [],
[{[<<"path">>, user], [], match, []}]}], [{[<<"path">>, user], [], match, []}]}],
{ok, _, [], [{user, <<"essen">>}], _, _} = match(Dispatch2, {ok, _, [], #{user := <<"essen">>}, _, _} = match(Dispatch2,
<<"essen.ninenines.eu">>, <<"/path/essen">>), <<"essen.ninenines.eu">>, <<"/path/essen">>),
{ok, _, [], [{user, <<"essen">>}], _, _} = match(Dispatch2, {ok, _, [], #{user := <<"essen">>}, _, _} = match(Dispatch2,
<<"essen.ninenines.eu">>, <<"/path/essen/">>), <<"essen.ninenines.eu">>, <<"/path/essen/">>),
{error, notfound, path} = match(Dispatch2, {error, notfound, path} = match(Dispatch2,
<<"essen.ninenines.eu">>, <<"/path/notessen">>), <<"essen.ninenines.eu">>, <<"/path/notessen">>),
Dispatch3 = [{'_', [], [{[same, same], [], match, []}]}], Dispatch3 = [{'_', [], [{[same, same], [], match, []}]}],
{ok, _, [], [{same, <<"path">>}], _, _} = match(Dispatch3, {ok, _, [], #{same := <<"path">>}, _, _} = match(Dispatch3,
<<"ninenines.eu">>, <<"/path/path">>), <<"ninenines.eu">>, <<"/path/path">>),
{error, notfound, path} = match(Dispatch3, {error, notfound, path} = match(Dispatch3,
<<"ninenines.eu">>, <<"/path/to">>), <<"ninenines.eu">>, <<"/path/to">>),