Skip to content

Commit 1512481

Browse files
authored
Merge pull request #115 from paulo-ferraz-oliveira/feature/ct
Move EUnit to CT
2 parents 1da924b + 9fe89e7 commit 1512481

18 files changed

+484
-499
lines changed

.github/workflows/main.yml

+10-4
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,19 @@ jobs:
5151

5252
- name: Compile
5353
run: rebar3 compile
54-
- name: EUnit tests
55-
run: rebar3 eunit
56-
- name: Dialyzer
57-
run: rebar3 dialyzer
54+
5855
- name: XRef
5956
run: rebar3 xref
6057

58+
- name: Dialyzer
59+
run: rebar3 dialyzer
60+
61+
- name: Elvis
62+
run: rebar3 lint
63+
64+
- name: Common Test
65+
run: rebar3 do ct, cover
66+
6167
- name: Covertool
6268
run: rebar3 covertool generate
6369
- uses: codecov/codecov-action@v4

.gitignore

-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
doc/*.html
33
!doc/tpl.html
44
_build
5-
deps/**
6-
ebin/**
7-
*.beam
8-
.eunit
9-
*~
10-
#*
115
.dialyzer.plt
126
.rebar
137
rebar3.crashdump

priv/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../README.md

rebar.config

+14-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,20 @@
1616
]}
1717
]},
1818
{test, [
19-
{deps, [{hackney, "1.20.1"}]}
19+
{deps, [{hackney, "1.20.1"}]},
20+
{extra_src_dirs, [
21+
{"test", [
22+
{recursive, true}
23+
]}
24+
]},
25+
{cover_enabled, true},
26+
{cover_export_enabled, true},
27+
{cover_excl_mods, [
28+
elli_handler
29+
]},
30+
{covertool, [{coverdata_files, ["ct.coverdata"]}]},
31+
{cover_opts, [verbose]},
32+
{ct_opts, [{ct_hooks, [cth_surefire]}]}
2033
]}
2134
]}.
2235

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

33-
{cover_enabled, true}.
34-
{cover_export_enabled, true}.
35-
{cover_excl_mods, [
36-
elli_handler
37-
]}.
38-
{covertool, [{coverdata_files, ["eunit.coverdata"]}]}.
39-
4046
{post_hooks, [{edoc, "doc/build.sh"}]}.
41-
42-
{ct_opts, [{ct_hooks, [cth_surefire]}]}.

src/elli_example_callback.erl

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ handle('GET', [<<"decoded-list">>], Req) ->
135135
handle('GET', [<<"sendfile">>], _Req) ->
136136
%% Returning {file, "/path/to/file"} instead of the body results
137137
%% in Elli using sendfile.
138-
F = "README.md",
138+
F = filename:join(code:priv_dir(elli), "README.md"),
139139
{ok, [], {file, F}};
140140

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

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

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

158158
handle('GET', [<<"compressed">>], _Req) ->

src/elli_http.erl

+4-18
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727

2828
-export_type([version/0]).
2929

30+
-ifdef(TEST).
31+
-export([get_body/5]).
32+
-endif.
33+
3034
%% @type version(). HTTP version as a tuple, i.e. `{0, 9} | {1, 0} | {1, 1}'.
3135
-type version() :: {0, 9} | {1, 0} | {1, 1}.
3236

@@ -895,21 +899,3 @@ status(510) -> <<"510 Not Extended">>;
895899
status(511) -> <<"511 Network Authentication Required">>;
896900
status(I) when is_integer(I), I >= 100, I < 1000 -> list_to_binary(io_lib:format("~B Status", [I]));
897901
status(B) when is_binary(B) -> B.
898-
899-
900-
%%
901-
%% UNIT TESTS
902-
%%
903-
904-
-ifdef(TEST).
905-
-include_lib("eunit/include/eunit.hrl").
906-
907-
get_body_test() ->
908-
Socket = undefined,
909-
Headers = [{<<"Content-Length">>, <<" 42 ">>}],
910-
Buffer = binary:copy(<<".">>, 42),
911-
Opts = [],
912-
Callback = {no_mod, []},
913-
?assertMatch({Buffer, <<>>},
914-
get_body(Socket, Headers, Buffer, Opts, Callback)).
915-
-endif.

src/elli_test.erl

-20
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,3 @@ call(Method, Path, Headers, Body, Opts) ->
2525
Body, {1, 1}, undefined, {Callback, CallbackArgs}),
2626
ok = Callback:handle_event(elli_startup, [], CallbackArgs),
2727
Callback:handle(Req, CallbackArgs).
28-
29-
-ifdef(TEST).
30-
-include_lib("eunit/include/eunit.hrl").
31-
32-
hello_world_test() ->
33-
?assertMatch({ok, [], <<"Hello World!">>},
34-
elli_test:call('GET', <<"/hello/world/">>, [], <<>>,
35-
?EXAMPLE_CONF)),
36-
?assertMatch({ok, [], <<"Hello Test1">>},
37-
elli_test:call('GET', <<"/hello/?name=Test1">>, [], <<>>,
38-
?EXAMPLE_CONF)),
39-
?assertMatch({ok,
40-
[{<<"content-type">>,
41-
<<"application/json; charset=ISO-8859-1">>}],
42-
<<"{\"name\" : \"Test2\"}">>},
43-
elli_test:call('GET', <<"/type?name=Test2">>,
44-
[{<<"accept">>, <<"application/json">>}], <<>>,
45-
?EXAMPLE_CONF)).
46-
47-
-endif. %% TEST

0 commit comments

Comments
 (0)