Skip to content

Commit

Permalink
make sure "rebar eunit" passes
Browse files Browse the repository at this point in the history
When using yaws as an app dependency for another application built with
rebar, I noticed that testing that application with "rebar eunit" would
fail while testing yaws. It was easy to work around with "rebar eunit
skip_deps=true" but yaws really should pass its tests when tested via
rebar.

Change rebar.config to add ibrowse as a dependency. It's used only for
testing, but rebar doesn't support test-only dependencies, plus it's
filtered out during release generation anyway.

Modify some of the test files to be able to find ibrowse include files
regardless of whether they're built via make or via rebar. Also rename all
non-eunit test functions ending in "_test" so they don't confuse eunit. Also
had to move the embedded_yaws_id_dir test from eunit to t2 because it fails
under "rebar eunit" when yaws is a dependency for another app. It fails
because it calls into the yaws_api:embedded_start_conf function which tries
to call application:load(yaws), but paths aren't properly set up to allow
that to work under these testing circumstances.

Note that not all tests currently run under rebar; building with make and
then running "make test" results in many more tests being executed. Fixing
this will come later.
  • Loading branch information
vinoski committed Aug 25, 2012
1 parent d0a90a9 commit 66f50e6
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 97 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -72,3 +72,4 @@ yaws_logs
rel/yaws
dialyzer_warnings
deps/*
.eunit/*
5 changes: 5 additions & 0 deletions rebar.config
Expand Up @@ -22,3 +22,8 @@

{pre_hooks, [{compile, "./scripts/rebar-pre-script"},
{clean, "./scripts/rebar-pre-script clean"}]}.

{deps,
[
{ibrowse, ".*", {git, "git://github.com/cmullaparthi/ibrowse.git", "HEAD"}}
]}.
1 change: 0 additions & 1 deletion test/eunit/Makefile
Expand Up @@ -3,7 +3,6 @@ include ../support/include.mk
OBJ := multipart_post_parsing.beam \
yaws_session_server_test.beam \
ehtml_test.beam \
embedded_yaws_id_dir.beam \
cookies.beam \
headers.beam

Expand Down
16 changes: 14 additions & 2 deletions test/eunit/cookies.erl
Expand Up @@ -284,12 +284,24 @@ set_cookie_expires_test() ->
ok.

real_cookies_test() ->
{ok, Io} = file:open("cookies.dump", read),
{ok, Io} = case file:open("cookies.dump", read) of
{error, _} ->
%% handle eunit testing under rebar
file:open("../test/eunit/cookies.dump", read);
Else ->
Else
end,
?assertEqual(ok, parse_cookies(Io, file:read_line(Io), 1)),
ok.

real_setcookies_test() ->
{ok, Io} = file:open("setcookies.dump", read),
{ok, Io} = case file:open("setcookies.dump", read) of
{error, _} ->
%% handle eunit testing under rebar
file:open("../test/eunit/setcookies.dump", read);
Else ->
Else
end,
?assertEqual(ok, parse_set_cookies(Io, file:read_line(Io), 1)),
ok.

Expand Down
24 changes: 0 additions & 24 deletions test/eunit/embedded_yaws_id_dir.erl

This file was deleted.

2 changes: 1 addition & 1 deletion test/support/include.mk.in
Expand Up @@ -8,7 +8,7 @@ YAWS=$(YTOP)/bin/yaws

SUBST=../../scripts/Subst

COMPILER_PA = -pa $(YTOP)/ebin
COMPILER_PA = -pa $(YTOP)/ebin -pa $(YTOP)/test/ibrowse/ebin

%.beam: %.erl
"$(ERLC)" -Ddebug $(COMPILER_PA) $<
Expand Down
91 changes: 56 additions & 35 deletions test/t2/app_test.erl
@@ -1,6 +1,6 @@
-module(app_test).
-include("../include/tftest.hrl").
-include("../ibrowse/include/ibrowse.hrl").
-include_lib("ibrowse/include/ibrowse.hrl").
-compile(export_all).


Expand All @@ -13,27 +13,28 @@ start([F]) ->
start() ->
io:format("\n ==== MAIN TESTS ==== \n\n", []),
?line {ok, _} = ibrowse:start_link(),
server_options_test(),
test_server_options(),
test1(),
test2(),
test3(),
appmod_test(),
streamcontent_test(),
test_appmod(),
test_streamcontent(),
sendfile_get(),
json_test(),
post_test(),
flush_test(),
expires_test(),
reentrant_test(),
cgi_redirect_test(),
php_handler_test(),
arg_rewrite_test(),
shaper_test(),
sslaccept_timeout_test(),
throw_test(),
too_many_headers_test(),
index_files_test(),
websocket_test(),
test_json(),
test_post(),
test_flush(),
test_expires(),
test_reentrant(),
test_cgi_redirect(),
test_php_handler(),
test_arg_rewrite(),
test_shaper(),
test_sslaccept_timeout(),
test_throw(),
test_too_many_headers(),
test_index_files(),
test_websocket(),
test_embedded_id_dir(),
ibrowse:stop().


Expand Down Expand Up @@ -137,7 +138,7 @@ test3() ->
[], head),
ok.

server_options_test() ->
test_server_options() ->
io:format("server_options_test\n",[]),
{ok, S} = gen_tcp:connect("localhost", 8000, [{packet, raw}, list,
{active, false}]),
Expand Down Expand Up @@ -227,7 +228,7 @@ collect(L, Count, Tag) ->

-define(APPMOD_HEADER, "Appmod-Called").

appmod_test() ->
test_appmod() ->
io:format("appmod_test\n",[]),
Uri1 = "http://localhost:8002/",
?line {ok, "200", Headers1, _} = ibrowse:send_req(Uri1, [], get),
Expand All @@ -243,7 +244,7 @@ appmod_test() ->
?line "true" = proplists:get_value(?APPMOD_HEADER, Headers4),
ok.

streamcontent_test() ->
test_streamcontent() ->
io:format("streamcontent_test\n",[]),
Uri1 = "http://localhost:8000/streamtest/1",
?line {ok, "200", Headers1, Body1} = ibrowse:send_req(Uri1, [], get),
Expand Down Expand Up @@ -282,7 +283,7 @@ streamcontent_test() ->

-define(JSON_URI, "http://localhost:8005/jsontest").

json_test() ->
test_json() ->
io:format("json_test\n",[]),
io:format(" param array1\n", []),
?line ok = do_json({struct, [{"jsonrpc", "2.0"},
Expand Down Expand Up @@ -527,7 +528,7 @@ recv_hdrs(Sock, Len) ->


%% partial_post_size = 2048000
post_test() ->
test_post() ->
io:format("post_test\n",[]),
small_post(),
large_post(),
Expand Down Expand Up @@ -579,7 +580,7 @@ large_chunked_post() ->
?line {ok, "200", _, _} = ibrowse:send_req(Uri, Hdrs, post, Bin, Opts2),
ok.

flush_test() ->
test_flush() ->
io:format("flush_test\n",[]),
flush_small_post(),
flush_large_post(),
Expand Down Expand Up @@ -666,7 +667,7 @@ flush_chunked_get() ->
ok.


expires_test() ->
test_expires() ->
io:format("expires_test\n", []),
Uri = "http://localhost:8006/hello.txt",
?line {ok, "200", Hdrs, _} = ibrowse:send_req(Uri, [], get),
Expand All @@ -688,7 +689,7 @@ expires_test() ->
ok.


reentrant_test() ->
test_reentrant() ->
io:format("reentrant_test\n", []),
reentrant_test_status(),
reentrant_test_delayed_headers(),
Expand All @@ -709,22 +710,22 @@ reentrant_test_delayed_headers() ->
?line "true" = proplists:get_value("X-Delayed-Header", Hdrs),
ok.

cgi_redirect_test() ->
test_cgi_redirect() ->
io:format("cgi_redirect_test\n", []),
Uri = "http://localhost:8008/cgi-bin/redirect_test.cgi",
?line {ok, "302", Hdrs, _} = ibrowse:send_req(Uri, [], get),
?line true = lists:any(fun({"Location", _}) -> true; (_) -> false end, Hdrs),
ok.

php_handler_test() ->
test_php_handler() ->
io:format("php_handler_test\n", []),
Uri = "http://localhost:8006/test.php",
{ok, Binary} = file:read_file("./www/test.php"),
Content = binary_to_list(Binary),
?line {ok, "200", _, Content} = ibrowse:send_req(Uri, [], get),
ok.

arg_rewrite_test() ->
test_arg_rewrite() ->
io:format("arg_rewrite_test\n", []),
arg_rewrite_test_rewrite(),
arg_rewrite_test_redirect(),
Expand Down Expand Up @@ -759,7 +760,7 @@ arg_rewrite_test_response() ->



shaper_test() ->
test_shaper() ->
io:format("shaper_test\n", []),
Uri = "http://localhost:8007/",
?line {ok, "200", _, _} = ibrowse:send_req(Uri, [], get),
Expand All @@ -770,7 +771,7 @@ shaper_test() ->



sslaccept_timeout_test() ->
test_sslaccept_timeout() ->
io:format("sslaccept_tout_test\n", []),
{ok, Sock} = gen_tcp:connect("localhost", 8443, [binary, {active, true}]),
?line ok = receive
Expand All @@ -783,21 +784,21 @@ sslaccept_timeout_test() ->
gen_tcp:close(Sock),
ok.

throw_test() ->
test_throw() ->
io:format("throw test\n", []),
Uri = "http://localhost:8009/",
?line {ok, "500", _, _} = ibrowse:send_req(Uri, [], get),
ok.

too_many_headers_test() ->
test_too_many_headers() ->
io:format("too many request headers test\n", []),
Uri = "http://localhost:8009/",
Hdrs = [{link, "<compact.css>; rel=\"stylesheet\"; title=\"compact\""} || _ <- lists:seq(0, 1001)],
?line {ok, "431", _, _} = ibrowse:send_req(Uri, Hdrs, get),
ok.


index_files_test() ->
test_index_files() ->
io:format("index_files test\n", []),
%% "/" should be redirected to "/testdir", then to "/testdir/" and finally
%% get "/testdir/index.html"
Expand All @@ -815,7 +816,7 @@ index_files_test() ->

%% Do handshake, then send "hello" in a text frame
%% and check that "hello" is echoed back.
websocket_test() ->
test_websocket() ->
OpenHeads = "GET /websockets_example_endpoint.yaws HTTP/1.1\r\n"
"Host: localhost\r\n"
"Upgrade: websocket\r\n"
Expand Down Expand Up @@ -846,6 +847,26 @@ websocket_test() ->
ExpectFrame = <<129, 5, "hello">>,
{ok, ExpectFrame} = gen_tcp:recv(Sock, 0, 2000).

test_embedded_id_dir() ->
Id = "id_dir_test",
GconfList = [{id, Id},
{logdir, "./logs"},
{ebin_dir, ["./ebin"]}],
Docroot = yaws:tmpdir(),
SconfList = [{port, 9999},
{servername, Id},
{listen, {127,0,0,1}},
{docroot, Docroot}],
{ok, _SCList, _GC, _ChildSpecs} = yaws_api:embedded_start_conf(
Docroot, SconfList, GconfList, Id),
try
{ok,
{file_info, _, directory, read_write, _, _, _, _, _, _, _, _, _, _}} =
file:read_file_info(yaws:id_dir(Id)),
ok
after
ok = file:del_dir(yaws:id_dir(Id))
end.

%% used for appmod tests
%%
Expand Down
2 changes: 1 addition & 1 deletion test/t3/app_test.erl
@@ -1,6 +1,6 @@
-module(app_test).
-include("../include/tftest.hrl").
-include("../ibrowse/include/ibrowse.hrl").
-include_lib("ibrowse/include/ibrowse.hrl").
-compile(export_all).


Expand Down

0 comments on commit 66f50e6

Please sign in to comment.