SisMaker пре 3 година
родитељ
комит
98b3f85740
5 измењених фајлова са 2 додато и 190 уклоњено
  1. +1
    -1
      README.md
  2. +1
    -1
      src/eWSrv.app.src
  3. +0
    -52
      src/test/elli_handover_tests.erl
  4. +0
    -34
      src/test/elli_metrics_middleware.erl
  5. +0
    -102
      src/test/elli_middleware_tests.erl

+ 1
- 1
README.md Прегледај датотеку

@ -1,7 +1,7 @@
eWSrv
=====
An erlang web server
An erlang's http1.1 server
Build
-----

+ 1
- 1
src/eWSrv.app.src Прегледај датотеку

@ -1,5 +1,5 @@
{application, eWSrv,
[{description, "erlang web server"},
[{description, "erlang http1.1 server"},
{vsn, "0.1.0"},
{registered, []},
{mod, {eWSrv_app, []}},

+ 0
- 52
src/test/elli_handover_tests.erl Прегледај датотеку

@ -1,52 +0,0 @@
-module(elli_handover_tests).
-include_lib("eunit/include/eunit.hrl").
-include("elli_test.hrl").
elli_test_() ->
{setup,
fun setup/0, fun teardown/1,
[
?_test(hello_world()),
?_test(echo())
]}.
setup() ->
application:start(crypto),
application:start(public_key),
application:start(ssl),
{ok, _} = application:ensure_all_started(hackney),
Config = [
{mods, [
{elli_example_callback_handover, []}
]}
],
{ok, P} = elli:start_link([{callback, elli_middleware},
{callback_args, Config},
{port, 3003}]),
unlink(P),
[P].
teardown(Pids) ->
[elli:stop(P) || P <- Pids].
%%
%% INTEGRATION TESTS
%% Uses hackney to actually call Elli over the network
%%
hello_world() ->
Response = hackney:get("http://localhost:3003/hello/world"),
?assertMatch(200, status(Response)),
?assertMatch([{<<"Connection">>, <<"close">>},
{<<"Content-Length">>, <<"12">>}], headers(Response)),
?assertMatch(<<"Hello World!">>, body(Response)).
echo() ->
Response = hackney:get("http://localhost:3003/hello?name=knut"),
?assertMatch(200, status(Response)),
?assertMatch(<<"Hello knut">>, body(Response)).

+ 0
- 34
src/test/elli_metrics_middleware.erl Прегледај датотеку

@ -1,34 +0,0 @@
-module(elli_metrics_middleware).
-export([init/2, preprocess/2, handle/2, postprocess/3, handle_event/3]).
-behaviour(wsHer).
%%
%% ELLI
%%
init(_Req, _Args) ->
ignore.
preprocess(Req, _Args) ->
Req.
handle(_Req, _Args) ->
ignore.
postprocess(_Req, Res, _Args) ->
Res.
%%
%% ELLI EVENT CALLBACKS
%%
handle_event(request_complete, [_Req, _C, _Hs, _B, {Timings, Sizes}], _) ->
ets:insert(elli_stat_table, {timings, Timings}),
ets:insert(elli_stat_table, {sizes, Sizes});
handle_event(chunk_complete, [_Req, _C, _Hs, _B, {Timings, Sizes}], _) ->
ets:insert(elli_stat_table, {timings, Timings}),
ets:insert(elli_stat_table, {sizes, Sizes});
handle_event(_Event, _Data, _Args) ->
ok.

+ 0
- 102
src/test/elli_middleware_tests.erl Прегледај датотеку

@ -1,102 +0,0 @@
-module(elli_middleware_tests).
-include_lib("eunit/include/eunit.hrl").
-include("elli_test.hrl").
elli_test_() ->
{setup,
fun setup/0, fun teardown/1,
[
?_test(hello_world()),
?_test(short_circuit()),
?_test(compress()),
?_test(no_callbacks())
]}.
%%
%% TESTS
%%
short_circuit() ->
URL = "http://localhost:3002/middleware/short-circuit",
Response = hackney:get(URL),
?assertMatch(<<"short circuit!">>, body(Response)).
hello_world() ->
URL = "http://localhost:3002/hello/world",
Response = hackney:get(URL),
?assertMatch(<<"Hello World!">>, body(Response)).
compress() ->
Url = "http://localhost:3002/compressed",
Headers = [{<<"Accept-Encoding">>, <<"gzip">>}],
Response = hackney:get(Url, Headers),
?assertHeadersEqual([{<<"Connection">>, <<"Keep-Alive">>},
{<<"Content-Encoding">>, <<"gzip">>},
{<<"Content-Length">>, <<"41">>}],
headers(Response)),
?assertEqual(binary:copy(<<"Hello World!">>, 86),
zlib:gunzip(body(Response))),
Response1 = hackney:get("http://localhost:3002/compressed"),
?assertHeadersEqual([{<<"Connection">>, <<"Keep-Alive">>},
{<<"Content-Length">>, <<"1032">>}],
headers(Response1)),
?assertEqual(iolist_to_binary(lists:duplicate(86, "Hello World!")),
body(Response1)),
Url2 = "http://localhost:3002/compressed-io_list",
Headers2 = [{<<"Accept-Encoding">>, <<"gzip">>}],
Response2 = hackney:get(Url2, Headers2),
?assertMatch(200, status(Response2)),
?assertHeadersEqual([{<<"Connection">>, <<"Keep-Alive">>},
{<<"Content-Encoding">>, <<"gzip">>},
{<<"Content-Length">>, <<"41">>}],
headers(Response2)),
?assertEqual(binary:copy(<<"Hello World!">>, 86),
zlib:gunzip(body(Response2))),
Response3 = hackney:request("http://localhost:3002/compressed-io_list"),
?assertMatch(200, status(Response3)),
?assertHeadersEqual([{<<"Connection">>, <<"Keep-Alive">>},
{<<"Content-Length">>, <<"1032">>}],
headers(Response3)),
?assertEqual(iolist_to_binary(lists:duplicate(86, "Hello World!")),
body(Response3)).
no_callbacks() ->
Response = hackney:get("http://localhost:3004/whatever"),
?assertMatch(404, status(Response)),
?assertMatch(<<"Not Found">>, body(Response)).
%%
%% HELPERS
%%
setup() ->
application:start(crypto),
application:start(public_key),
application:start(ssl),
{ok, _} = application:ensure_all_started(hackney),
Config = [
{mods, [
{elli_access_log, [{name, elli_syslog},
{ip, "127.0.0.1"},
{port, 514}]},
{elli_example_middleware, []},
{elli_middleware_compress, []},
{elli_example_callback, []}
]}
],
{ok, P1} = elli:start_link([{callback, elli_middleware},
{callback_args, Config},
{port, 3002}]),
unlink(P1),
{ok, P2} = elli:start_link([{callback, elli_middleware},
{callback_args, [{mods, []}]},
{port, 3004}]),
unlink(P2),
[P1, P2].
teardown(Pids) ->
[elli:stop(P) || P <- Pids].

Loading…
Откажи
Сачувај