mirror of
https://github.com/ninenines/cowboy.git
synced 2025-07-14 12:20:24 +00:00
Removed asserts from unit tests
This commit is contained in:
parent
61b3157ad1
commit
3bf5b46786
8 changed files with 64 additions and 82 deletions
2
Makefile
2
Makefile
|
@ -84,7 +84,7 @@ CT_RUN = ct_run \
|
||||||
-logdir logs
|
-logdir logs
|
||||||
# -cover test/cover.spec
|
# -cover test/cover.spec
|
||||||
|
|
||||||
tests: ERLC_OPTS += -DTEST=1
|
tests: ERLC_OPTS += -DTEST=1 +'{parse_transform, eunit_autoexport}'
|
||||||
tests: clean clean-deps deps app build-tests
|
tests: clean clean-deps deps app build-tests
|
||||||
@mkdir -p logs/
|
@mkdir -p logs/
|
||||||
@$(CT_RUN) -suite eunit_SUITE http_SUITE ws_SUITE
|
@$(CT_RUN) -suite eunit_SUITE http_SUITE ws_SUITE
|
||||||
|
|
|
@ -24,10 +24,6 @@
|
||||||
-export([char_to_lower/1]).
|
-export([char_to_lower/1]).
|
||||||
-export([char_to_upper/1]).
|
-export([char_to_upper/1]).
|
||||||
|
|
||||||
-ifdef(TEST).
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
|
||||||
-endif.
|
|
||||||
|
|
||||||
%% @doc Capitalize a token.
|
%% @doc Capitalize a token.
|
||||||
%%
|
%%
|
||||||
%% The first letter and all letters after a dash are capitalized.
|
%% The first letter and all letters after a dash are capitalized.
|
||||||
|
|
|
@ -45,10 +45,6 @@
|
||||||
-define(SERVER, ?MODULE).
|
-define(SERVER, ?MODULE).
|
||||||
-define(TABLE, ?MODULE).
|
-define(TABLE, ?MODULE).
|
||||||
|
|
||||||
-ifdef(TEST).
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
|
||||||
-endif.
|
|
||||||
|
|
||||||
%% API.
|
%% API.
|
||||||
|
|
||||||
%% @private
|
%% @private
|
||||||
|
|
|
@ -60,10 +60,6 @@
|
||||||
-export_type([headers/0]).
|
-export_type([headers/0]).
|
||||||
-export_type([status/0]).
|
-export_type([status/0]).
|
||||||
|
|
||||||
-ifdef(TEST).
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
|
||||||
-endif.
|
|
||||||
|
|
||||||
%% Parsing.
|
%% Parsing.
|
||||||
|
|
||||||
%% @doc Parse a non-empty list of the given type.
|
%% @doc Parse a non-empty list of the given type.
|
||||||
|
@ -1319,40 +1315,53 @@ x_www_form_urlencoded_test_() ->
|
||||||
[{Qs, fun() -> R = x_www_form_urlencoded(Qs) end} || {Qs, R} <- Tests].
|
[{Qs, fun() -> R = x_www_form_urlencoded(Qs) end} || {Qs, R} <- Tests].
|
||||||
|
|
||||||
urldecode_test_() ->
|
urldecode_test_() ->
|
||||||
U = fun urldecode/2,
|
F = fun(Qs, O) ->
|
||||||
[?_assertEqual(<<" ">>, U(<<"%20">>, crash)),
|
try urldecode(Qs, O) of
|
||||||
?_assertEqual(<<" ">>, U(<<"+">>, crash)),
|
R ->
|
||||||
?_assertEqual(<<0>>, U(<<"%00">>, crash)),
|
{ok, R}
|
||||||
?_assertEqual(<<255>>, U(<<"%fF">>, crash)),
|
catch _:E ->
|
||||||
?_assertEqual(<<"123">>, U(<<"123">>, crash)),
|
{error, E}
|
||||||
?_assertEqual(<<"%i5">>, U(<<"%i5">>, skip)),
|
end
|
||||||
?_assertEqual(<<"%5">>, U(<<"%5">>, skip)),
|
end,
|
||||||
?_assertError(badarg, U(<<"%i5">>, crash)),
|
Tests = [
|
||||||
?_assertError(badarg, U(<<"%5">>, crash))
|
{<<"%20">>, crash, {ok, <<" ">>}},
|
||||||
].
|
{<<"+">>, crash, {ok, <<" ">>}},
|
||||||
|
{<<"%00">>, crash, {ok, <<0>>}},
|
||||||
|
{<<"%fF">>, crash, {ok, <<255>>}},
|
||||||
|
{<<"123">>, crash, {ok, <<"123">>}},
|
||||||
|
{<<"%i5">>, skip, {ok, <<"%i5">>}},
|
||||||
|
{<<"%5">>, skip, {ok, <<"%5">>}},
|
||||||
|
{<<"%i5">>, crash, {error, badarg}},
|
||||||
|
{<<"%5">>, crash, {error, badarg}}
|
||||||
|
],
|
||||||
|
[{Qs, fun() -> R = F(Qs,O) end} || {Qs, O, R} <- Tests].
|
||||||
|
|
||||||
urlencode_test_() ->
|
urlencode_test_() ->
|
||||||
U = fun urlencode/2,
|
Tests = [
|
||||||
[?_assertEqual(<<"%ff%00">>, U(<<255,0>>, [])),
|
{<<255,0>>, [], <<"%ff%00">>},
|
||||||
?_assertEqual(<<"%FF%00">>, U(<<255,0>>, [upper])),
|
{<<255,0>>, [upper], <<"%FF%00">>},
|
||||||
?_assertEqual(<<"+">>, U(<<" ">>, [])),
|
{<<" ">>, [], <<"+">>},
|
||||||
?_assertEqual(<<"%20">>, U(<<" ">>, [noplus])),
|
{<<" ">>, [noplus], <<"%20">>},
|
||||||
?_assertEqual(<<"aBc">>, U(<<"aBc">>, [])),
|
{<<"aBc">>, [], <<"aBc">>},
|
||||||
?_assertEqual(<<".-~_">>, U(<<".-~_">>, [])),
|
{<<".-~_">>, [], <<".-~_">>}
|
||||||
?_assertEqual(<<"%ff+">>, urlencode(<<255, " ">>))
|
],
|
||||||
].
|
Tests2 = [{<<255, " ">>,<<"%ff+">>}],
|
||||||
|
[{V, fun() -> R = urlencode(V, O) end} || {V, O, R} <- Tests] ++
|
||||||
|
[{V, fun() -> R = urlencode(V) end} || {V, R} <- Tests2].
|
||||||
|
|
||||||
http_authorization_test_() ->
|
http_authorization_test_() ->
|
||||||
[?_assertEqual({<<"basic">>, {<<"Alladin">>, <<"open sesame">>}},
|
Tests = [
|
||||||
authorization(<<"QWxsYWRpbjpvcGVuIHNlc2FtZQ==">>, <<"basic">>)),
|
{<<"basic">>, <<"QWxsYWRpbjpvcGVuIHNlc2FtZQ==">>,
|
||||||
?_assertEqual({error, badarg},
|
{<<"basic">>, {<<"Alladin">>, <<"open sesame">>}}},
|
||||||
authorization(<<"dXNlcm5hbWUK">>, <<"basic">>)),
|
{<<"basic">>, <<"dXNlcm5hbWUK">>,
|
||||||
?_assertEqual({error, badarg},
|
{error, badarg}},
|
||||||
authorization(<<"_[]@#$%^&*()-AA==">>, <<"basic">>)),
|
{<<"basic">>, <<"_[]@#$%^&*()-AA==">>,
|
||||||
?_assertEqual({error, badarg},
|
{error, badarg}},
|
||||||
authorization(<<"dXNlcjpwYXNzCA==">>, <<"basic">>)), %% user:pass\010
|
{<<"basic">>, <<"dXNlcjpwYXNzCA==">>,
|
||||||
?_assertEqual({<<"bearer">>,<<"some_secret_key">>},
|
{error, badarg}},
|
||||||
authorization(<<" some_secret_key">>, <<"bearer">>))
|
{<<"bearer">>, <<" some_secret_key">>,
|
||||||
].
|
{<<"bearer">>,<<"some_secret_key">>}}
|
||||||
|
],
|
||||||
|
[{V, fun() -> R = authorization(V,T) end} || {T, V, R} <- Tests].
|
||||||
|
|
||||||
-endif.
|
-endif.
|
||||||
|
|
|
@ -30,10 +30,6 @@
|
||||||
-type end_of_part() :: {end_of_part, cont(more(part_result()))}.
|
-type end_of_part() :: {end_of_part, cont(more(part_result()))}.
|
||||||
-type disposition() :: {binary(), [{binary(), binary()}]}.
|
-type disposition() :: {binary(), [{binary(), binary()}]}.
|
||||||
|
|
||||||
-ifdef(TEST).
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
|
||||||
-endif.
|
|
||||||
|
|
||||||
%% API.
|
%% API.
|
||||||
|
|
||||||
%% @doc Return a multipart parser for the given boundary.
|
%% @doc Return a multipart parser for the given boundary.
|
||||||
|
@ -298,8 +294,7 @@ title(Bin) ->
|
||||||
iolist_to_binary(Title).
|
iolist_to_binary(Title).
|
||||||
|
|
||||||
suffix_test_() ->
|
suffix_test_() ->
|
||||||
[?_assertEqual(Part, suffix_match(Packet, pattern(Boundary))) ||
|
Tests = [
|
||||||
{Part, Packet, Boundary} <- [
|
|
||||||
{nomatch, <<>>, <<"ABC">>},
|
{nomatch, <<>>, <<"ABC">>},
|
||||||
{{0, 1}, <<"\r">>, <<"ABC">>},
|
{{0, 1}, <<"\r">>, <<"ABC">>},
|
||||||
{{0, 2}, <<"\r\n">>, <<"ABC">>},
|
{{0, 2}, <<"\r\n">>, <<"ABC">>},
|
||||||
|
@ -311,6 +306,8 @@ suffix_test_() ->
|
||||||
{{1, 1}, <<"1\r">>, <<"ABC">>},
|
{{1, 1}, <<"1\r">>, <<"ABC">>},
|
||||||
{{2, 2}, <<"12\r\n">>, <<"ABC">>},
|
{{2, 2}, <<"12\r\n">>, <<"ABC">>},
|
||||||
{{3, 4}, <<"123\r\n--">>, <<"ABC">>}
|
{{3, 4}, <<"123\r\n--">>, <<"ABC">>}
|
||||||
]].
|
],
|
||||||
|
[fun() -> Part = suffix_match(Packet, pattern(Boundary)) end ||
|
||||||
|
{Part, Packet, Boundary} <- Tests].
|
||||||
|
|
||||||
-endif.
|
-endif.
|
||||||
|
|
|
@ -115,10 +115,6 @@
|
||||||
-export([lock/1]).
|
-export([lock/1]).
|
||||||
-export([to_list/1]).
|
-export([to_list/1]).
|
||||||
|
|
||||||
-ifdef(TEST).
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
|
||||||
-endif.
|
|
||||||
|
|
||||||
-type cookie_option() :: {max_age, non_neg_integer()}
|
-type cookie_option() :: {max_age, non_neg_integer()}
|
||||||
| {domain, binary()} | {path, binary()}
|
| {domain, binary()} | {path, binary()}
|
||||||
| {secure, boolean()} | {http_only, boolean()}.
|
| {secure, boolean()} | {http_only, boolean()}.
|
||||||
|
@ -1471,26 +1467,20 @@ connection_to_atom_test_() ->
|
||||||
[{lists:flatten(io_lib:format("~p", [T])),
|
[{lists:flatten(io_lib:format("~p", [T])),
|
||||||
fun() -> R = connection_to_atom(T) end} || {T, R} <- Tests].
|
fun() -> R = connection_to_atom(T) end} || {T, R} <- Tests].
|
||||||
|
|
||||||
merge_headers_test() ->
|
merge_headers_test_() ->
|
||||||
Left0 = [{<<"content-length">>,<<"13">>},{<<"server">>,<<"Cowboy">>}],
|
Tests = [
|
||||||
Right0 = [{<<"set-cookie">>,<<"foo=bar">>},{<<"content-length">>,<<"11">>}],
|
{[{<<"content-length">>,<<"13">>},{<<"server">>,<<"Cowboy">>}],
|
||||||
|
[{<<"set-cookie">>,<<"foo=bar">>},{<<"content-length">>,<<"11">>}],
|
||||||
?assertMatch(
|
[{<<"set-cookie">>,<<"foo=bar">>},
|
||||||
[{<<"set-cookie">>,<<"foo=bar">>},
|
{<<"content-length">>,<<"13">>},
|
||||||
{<<"content-length">>,<<"13">>},
|
{<<"server">>,<<"Cowboy">>}]},
|
||||||
{<<"server">>,<<"Cowboy">>}],
|
{[{<<"content-length">>,<<"13">>},{<<"server">>,<<"Cowboy">>}],
|
||||||
merge_headers(Left0, Right0)),
|
[{<<"set-cookie">>,<<"foo=bar">>},{<<"set-cookie">>,<<"bar=baz">>}],
|
||||||
|
[{<<"set-cookie">>,<<"bar=baz">>},
|
||||||
Left1 = [{<<"content-length">>,<<"13">>},{<<"server">>,<<"Cowboy">>}],
|
{<<"set-cookie">>,<<"foo=bar">>},
|
||||||
Right1 = [{<<"set-cookie">>,<<"foo=bar">>},{<<"set-cookie">>,<<"bar=baz">>}],
|
{<<"content-length">>,<<"13">>},
|
||||||
|
{<<"server">>,<<"Cowboy">>}]}
|
||||||
?assertMatch(
|
],
|
||||||
[{<<"set-cookie">>,<<"bar=baz">>},
|
[fun() -> Res = merge_headers(L,R) end || {L, R, Res} <- Tests].
|
||||||
{<<"set-cookie">>,<<"foo=bar">>},
|
|
||||||
{<<"content-length">>,<<"13">>},
|
|
||||||
{<<"server">>,<<"Cowboy">>}],
|
|
||||||
merge_headers(Left1, Right1)),
|
|
||||||
|
|
||||||
ok.
|
|
||||||
|
|
||||||
-endif.
|
-endif.
|
||||||
|
|
|
@ -51,10 +51,6 @@
|
||||||
-opaque dispatch_rules() :: [dispatch_rule()].
|
-opaque dispatch_rules() :: [dispatch_rule()].
|
||||||
-export_type([dispatch_rules/0]).
|
-export_type([dispatch_rules/0]).
|
||||||
|
|
||||||
-ifdef(TEST).
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
|
||||||
-endif.
|
|
||||||
|
|
||||||
%% @doc Compile a list of routes into the dispatch format used
|
%% @doc Compile a list of routes into the dispatch format used
|
||||||
%% by Cowboy's routing.
|
%% by Cowboy's routing.
|
||||||
-spec compile(routes()) -> dispatch_rules().
|
-spec compile(routes()) -> dispatch_rules().
|
||||||
|
|
|
@ -422,8 +422,6 @@ attr_etag_function(Args, Attrs) ->
|
||||||
{strong, list_to_binary([H|T])}.
|
{strong, list_to_binary([H|T])}.
|
||||||
|
|
||||||
-ifdef(TEST).
|
-ifdef(TEST).
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
|
||||||
-define(_eq(E, I), ?_assertEqual(E, I)).
|
|
||||||
|
|
||||||
directory_path_test_() ->
|
directory_path_test_() ->
|
||||||
PL = fun(D) -> length(filename:split(directory_path(D))) end,
|
PL = fun(D) -> length(filename:split(directory_path(D))) end,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue