Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move EUnit to CT #115

Merged
merged 2 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .github/workflows/main.yml
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We go from eunit+dialyzer to xref+dialyzer+lint+ct+cover

Note: eunit was doing lint, as per rebar.config, but it's probably better to have it explicitly as a CI step.

Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,19 @@ jobs:

- name: Compile
run: rebar3 compile
- name: EUnit tests
run: rebar3 eunit
- name: Dialyzer
run: rebar3 dialyzer

- name: XRef
run: rebar3 xref

- name: Dialyzer
run: rebar3 dialyzer

- name: Elvis
run: rebar3 lint

- name: Common Test
run: rebar3 do ct, cover

- name: Covertool
run: rebar3 covertool generate
- uses: codecov/codecov-action@v4
Expand Down
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
doc/*.html
!doc/tpl.html
_build
deps/**
ebin/**
*.beam
.eunit
*~
#*
.dialyzer.plt
.rebar
rebar3.crashdump
1 change: 1 addition & 0 deletions priv/README.md
24 changes: 14 additions & 10 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,20 @@
]}
]},
{test, [
{deps, [{hackney, "1.20.1"}]}
{deps, [{hackney, "1.20.1"}]},
{extra_src_dirs, [
{"test", [
{recursive, true}
]}
]},
{cover_enabled, true},
{cover_export_enabled, true},
{cover_excl_mods, [
elli_handler
]},
{covertool, [{coverdata_files, ["ct.coverdata"]}]},
{cover_opts, [verbose]},
{ct_opts, [{ct_hooks, [cth_surefire]}]}
]}
]}.

Expand All @@ -30,13 +43,4 @@
{provider_hooks, [{pre, [{eunit, lint}]}]}.
{dialyzer, [{plt_extra_apps, [ssl]}, {warnings, [unknown]}]}.

{cover_enabled, true}.
{cover_export_enabled, true}.
{cover_excl_mods, [
elli_handler
]}.
{covertool, [{coverdata_files, ["eunit.coverdata"]}]}.

{post_hooks, [{edoc, "doc/build.sh"}]}.

{ct_opts, [{ct_hooks, [cth_surefire]}]}.
6 changes: 3 additions & 3 deletions src/elli_example_callback.erl
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ handle('GET', [<<"decoded-list">>], Req) ->
handle('GET', [<<"sendfile">>], _Req) ->
%% Returning {file, "/path/to/file"} instead of the body results
%% in Elli using sendfile.
F = "README.md",
F = filename:join(code:priv_dir(elli), "README.md"),
{ok, [], {file, F}};

handle('GET', [<<"send_no_file">>], _Req) ->
Expand All @@ -145,14 +145,14 @@ handle('GET', [<<"send_no_file">>], _Req) ->
{ok, [], {file, F}};

handle('GET', [<<"sendfile">>, <<"error">>], _Req) ->
F = "test",
F = code:priv_dir(elli),
{ok, [], {file, F}};

handle('GET', [<<"sendfile">>, <<"range">>], Req) ->
%% Read the Range header of the request and use the normalized
%% range with sendfile, otherwise send the entire file when
%% no range is present, or respond with a 416 if the range is invalid.
F = "README.md",
F = filename:join(code:priv_dir(elli), "README.md"),
{ok, [], {file, F, elli_request:get_range(Req)}};

handle('GET', [<<"compressed">>], _Req) ->
Expand Down
22 changes: 4 additions & 18 deletions src/elli_http.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@

-export_type([version/0]).

-ifdef(TEST).
-export([get_body/5]).
-endif.

%% @type version(). HTTP version as a tuple, i.e. `{0, 9} | {1, 0} | {1, 1}'.
-type version() :: {0, 9} | {1, 0} | {1, 1}.

Expand Down Expand Up @@ -895,21 +899,3 @@ status(510) -> <<"510 Not Extended">>;
status(511) -> <<"511 Network Authentication Required">>;
status(I) when is_integer(I), I >= 100, I < 1000 -> list_to_binary(io_lib:format("~B Status", [I]));
status(B) when is_binary(B) -> B.


%%
%% UNIT TESTS
%%

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").

get_body_test() ->
Socket = undefined,
Headers = [{<<"Content-Length">>, <<" 42 ">>}],
Buffer = binary:copy(<<".">>, 42),
Opts = [],
Callback = {no_mod, []},
?assertMatch({Buffer, <<>>},
get_body(Socket, Headers, Buffer, Opts, Callback)).
-endif.
20 changes: 0 additions & 20 deletions src/elli_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,3 @@ call(Method, Path, Headers, Body, Opts) ->
Body, {1, 1}, undefined, {Callback, CallbackArgs}),
ok = Callback:handle_event(elli_startup, [], CallbackArgs),
Callback:handle(Req, CallbackArgs).

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").

hello_world_test() ->
?assertMatch({ok, [], <<"Hello World!">>},
elli_test:call('GET', <<"/hello/world/">>, [], <<>>,
?EXAMPLE_CONF)),
?assertMatch({ok, [], <<"Hello Test1">>},
elli_test:call('GET', <<"/hello/?name=Test1">>, [], <<>>,
?EXAMPLE_CONF)),
?assertMatch({ok,
[{<<"content-type">>,
<<"application/json; charset=ISO-8859-1">>}],
<<"{\"name\" : \"Test2\"}">>},
elli_test:call('GET', <<"/type?name=Test2">>,
[{<<"accept">>, <<"application/json">>}], <<>>,
?EXAMPLE_CONF)).

-endif. %% TEST
Loading
Loading