123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- -module(autobahn_SUITE).
- -include_lib("common_test/include/ct.hrl").
- -export([all/0, groups/0, init_per_suite/1, end_per_suite/1,
- init_per_group/2, end_per_group/2]).
- -export([run_tests/1]).
- all() ->
- [{group, autobahn}].
- groups() ->
- BaseTests = [run_tests],
- [{autobahn, [], BaseTests}].
- init_per_suite(Config) ->
- application:start(inets),
- application:start(cowboy),
-
-
-
-
- EnvPath = "/tmp/cowboy_autobahn_env",
- os:putenv("AB_TESTS_ENV", EnvPath),
- os:putenv("AB_TESTS_PRIV", ?config(priv_dir, Config)),
- BinPath = filename:join(?config(data_dir, Config), "test.py"),
- Stdout = os:cmd(BinPath ++ " setup"),
- ct:log("~s~n", [Stdout]),
- case string:str(Stdout, "AB-TESTS-SETUP-OK") of
- 0 -> erlang:error(failed);
- _ -> [{env_path, EnvPath},{bin_path,BinPath}|Config]
- end.
- end_per_suite(_Config) ->
- os:cmd("deactivate"),
- application:stop(cowboy),
- application:stop(inets),
- ok.
- init_per_group(autobahn, Config) ->
- Port = 33080,
- cowboy:start_http(autobahn, 100, [{port, Port}], [
- {dispatch, init_dispatch()}
- ]),
- [{port, Port}|Config].
- end_per_group(Listener, _Config) ->
- cowboy:stop_listener(Listener),
- ok.
- init_dispatch() ->
- [{[<<"localhost">>], [
- {[<<"echo">>], websocket_echo_handler, []}]}].
- run_tests(Config) ->
- PrivDir = ?config(priv_dir, Config),
- IndexFile = filename:join([PrivDir, "reports", "servers", "index.html"]),
- ct:log("<h2><a href=\"~s\">Full Test Results Report</a></h2>~n", [IndexFile]),
- BinPath = ?config(bin_path, Config),
- Stdout = os:cmd(BinPath ++ " test"),
- ct:log("~s~n", [Stdout]),
- case string:str(Stdout, "AB-TESTS-TEST-OK") of
- 0 -> erlang:error(failed);
- _ -> ok
- end,
- {ok, IndexHTML} = file:read_file(IndexFile),
- case binary:match(IndexHTML, <<"Fail">>) of
- {_, _} -> erlang:error(failed);
- nomatch -> ok
- end.
|