aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/cowboy_test.erl28
-rw-r--r--test/http_SUITE.erl70
-rw-r--r--test/spdy_SUITE.erl11
-rw-r--r--test/ws_SUITE.erl15
4 files changed, 65 insertions, 59 deletions
diff --git a/test/cowboy_test.erl b/test/cowboy_test.erl
index 786eab6..4cb2a33 100644
--- a/test/cowboy_test.erl
+++ b/test/cowboy_test.erl
@@ -49,6 +49,34 @@ all(Suite) ->
string:substr(atom_to_list(F), 1, 3) =/= "do_"
]).
+%% Listeners initialization.
+
+init_http(Ref, ProtoOpts, Config) ->
+ {ok, _} = cowboy:start_http(Ref, 100, [{port, 0}], [
+ {max_keepalive, 50},
+ {timeout, 500}
+ |ProtoOpts]),
+ Port = ranch:get_port(Ref),
+ [{type, tcp}, {port, Port}, {opts, []}|Config].
+
+init_https(Ref, ProtoOpts, Config) ->
+ {_, Cert, Key} = ct_helper:make_certs(),
+ Opts = [{cert, Cert}, {key, Key}],
+ {ok, _} = cowboy:start_https(Ref, 100, Opts ++ [{port, 0}], [
+ {max_keepalive, 50},
+ {timeout, 500}
+ |ProtoOpts]),
+ Port = ranch:get_port(Ref),
+ [{type, ssl}, {port, Port}, {opts, Opts}|Config].
+
+init_spdy(Ref, ProtoOpts, Config) ->
+ {_, Cert, Key} = ct_helper:make_certs(),
+ Opts = [{cert, Cert}, {key, Key}],
+ {ok, _} = cowboy:start_spdy(Ref, 100, Opts ++ [{port, 0}],
+ ProtoOpts),
+ Port = ranch:get_port(Ref),
+ [{type, ssl}, {port, Port}, {opts, Opts}|Config].
+
%% Support functions for testing using Gun.
gun_open(Config) ->
diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl
index 70ae005..578b391 100644
--- a/test/http_SUITE.erl
+++ b/test/http_SUITE.erl
@@ -79,39 +79,26 @@ init_per_suite(Config) ->
end_per_suite(Config) ->
ct_helper:delete_static_dir(config(static_dir, Config)).
-init_tcp_group(Ref, ProtoOpts, Config) ->
- Transport = ranch_tcp,
- {ok, _} = cowboy:start_http(Ref, 100, [{port, 0}], [
+init_per_group(Name = http, Config) ->
+ cowboy_test:init_http(Name, [
+ {env, [{dispatch, init_dispatch(Config)}]}
+ ], Config);
+init_per_group(Name = https, Config) ->
+ cowboy_test:init_https(Name, [
+ {env, [{dispatch, init_dispatch(Config)}]}
+ ], Config);
+init_per_group(Name = http_compress, Config) ->
+ cowboy_test:init_http(Name, [
{env, [{dispatch, init_dispatch(Config)}]},
- {max_keepalive, 50},
- {timeout, 500}
- |ProtoOpts]),
- Port = ranch:get_port(Ref),
- [{type, tcp}, {port, Port}, {opts, []}, {transport, Transport}|Config].
-
-init_ssl_group(Ref, ProtoOpts, Config) ->
- Transport = ranch_ssl,
- {_, Cert, Key} = ct_helper:make_certs(),
- Opts = [{cert, Cert}, {key, Key}],
- {ok, _} = cowboy:start_https(Ref, 100, Opts ++ [{port, 0}], [
+ {compress, true}
+ ], Config);
+init_per_group(Name = https_compress, Config) ->
+ cowboy_test:init_https(Name, [
{env, [{dispatch, init_dispatch(Config)}]},
- {max_keepalive, 50},
- {timeout, 500}
- |ProtoOpts]),
- Port = ranch:get_port(Ref),
- [{type, ssl}, {port, Port}, {opts, Opts}, {transport, Transport}|Config].
-
-init_per_group(http, Config) ->
- init_tcp_group(http, [], Config);
-init_per_group(https, Config) ->
- init_ssl_group(https, [], Config);
-init_per_group(http_compress, Config) ->
- init_tcp_group(http_compress, [{compress, true}], Config);
-init_per_group(https_compress, Config) ->
- init_ssl_group(https_compress, [{compress, true}], Config);
+ {compress, true}
+ ], Config);
%% Most, if not all of these, should be in separate test suites.
init_per_group(onrequest, Config) ->
- Transport = ranch_tcp,
{ok, _} = cowboy:start_http(onrequest, 100, [{port, 0}], [
{env, [{dispatch, init_dispatch(Config)}]},
{max_keepalive, 50},
@@ -119,9 +106,8 @@ init_per_group(onrequest, Config) ->
{timeout, 500}
]),
Port = ranch:get_port(onrequest),
- [{type, tcp}, {port, Port}, {opts, []}, {transport, Transport}|Config];
+ [{type, tcp}, {port, Port}, {opts, []}|Config];
init_per_group(onresponse, Config) ->
- Transport = ranch_tcp,
{ok, _} = cowboy:start_http(onresponse, 100, [{port, 0}], [
{env, [{dispatch, init_dispatch(Config)}]},
{max_keepalive, 50},
@@ -129,9 +115,8 @@ init_per_group(onresponse, Config) ->
{timeout, 500}
]),
Port = ranch:get_port(onresponse),
- [{type, tcp}, {port, Port}, {opts, []}, {transport, Transport}|Config];
+ [{type, tcp}, {port, Port}, {opts, []}|Config];
init_per_group(onresponse_capitalize, Config) ->
- Transport = ranch_tcp,
{ok, _} = cowboy:start_http(onresponse_capitalize, 100, [{port, 0}], [
{env, [{dispatch, init_dispatch(Config)}]},
{max_keepalive, 50},
@@ -139,9 +124,8 @@ init_per_group(onresponse_capitalize, Config) ->
{timeout, 500}
]),
Port = ranch:get_port(onresponse_capitalize),
- [{type, tcp}, {port, Port}, {opts, []}, {transport, Transport}|Config];
+ [{type, tcp}, {port, Port}, {opts, []}|Config];
init_per_group(parse_host, Config) ->
- Transport = ranch_tcp,
Dispatch = cowboy_router:compile([
{'_', [
{"/req_attr", http_req_attr, []}
@@ -153,20 +137,18 @@ init_per_group(parse_host, Config) ->
{timeout, 500}
]),
Port = ranch:get_port(http),
- [{type, tcp}, {port, Port}, {opts, []}, {transport, Transport}|Config];
+ [{type, tcp}, {port, Port}, {opts, []}|Config];
init_per_group(set_env, Config) ->
- Transport = ranch_tcp,
{ok, _} = cowboy:start_http(set_env, 100, [{port, 0}], [
{env, [{dispatch, []}]},
{max_keepalive, 50},
{timeout, 500}
]),
Port = ranch:get_port(set_env),
- [{type, tcp}, {port, Port}, {opts, []}, {transport, Transport}|Config].
+ [{type, tcp}, {port, Port}, {opts, []}|Config].
end_per_group(Name, _) ->
- cowboy:stop_listener(Name),
- ok.
+ cowboy:stop_listener(Name).
%% Dispatch configuration.
@@ -436,8 +418,12 @@ http10_chunkless(Config) ->
http10_hostless(Config) ->
Port10 = config(port, Config) + 10,
Name = list_to_atom("http10_hostless_" ++ integer_to_list(Port10)),
- ranch:start_listener(Name, 5,
- config(transport, Config), config(opts, Config) ++ [{port, Port10}],
+ Transport = case config(type, Config) of
+ tcp -> ranch_tcp;
+ ssl -> ranch_ssl
+ end,
+ ranch:start_listener(Name, 5, Transport,
+ config(opts, Config) ++ [{port, Port10}],
cowboy_protocol, [
{env, [{dispatch, cowboy_router:compile([
{'_', [{"/http1.0/hostless", http_handler, []}]}])}]},
diff --git a/test/spdy_SUITE.erl b/test/spdy_SUITE.erl
index 8ed747a..2e9c7e4 100644
--- a/test/spdy_SUITE.erl
+++ b/test/spdy_SUITE.erl
@@ -40,17 +40,12 @@ end_per_suite(Config) ->
ct_helper:delete_static_dir(config(static_dir, Config)).
init_per_group(Name, Config) ->
- {_, Cert, Key} = ct_helper:make_certs(),
- Opts = [{cert, Cert}, {key, Key}],
- {ok, _} = cowboy:start_spdy(Name, 100, Opts ++ [{port, 0}], [
+ cowboy_test:init_spdy(Name, [
{env, [{dispatch, init_dispatch(Config)}]}
- ]),
- Port = ranch:get_port(Name),
- [{port, Port}, {type, ssl}|Config].
+ ], Config).
end_per_group(Name, _) ->
- cowboy:stop_listener(Name),
- ok.
+ cowboy:stop_listener(Name).
%% Dispatch configuration.
diff --git a/test/ws_SUITE.erl b/test/ws_SUITE.erl
index 8f4091c..77c82f6 100644
--- a/test/ws_SUITE.erl
+++ b/test/ws_SUITE.erl
@@ -29,7 +29,7 @@ groups() ->
init_per_suite(Config) ->
Config.
-init_per_group(autobahn, Config) ->
+init_per_group(Name = autobahn, Config) ->
%% Some systems have it named pip2.
Out = os:cmd("pip show autobahntestsuite ; pip2 show autobahntestsuite"),
case string:str(Out, "autobahntestsuite") of
@@ -40,21 +40,18 @@ init_per_group(autobahn, Config) ->
"http://autobahn.ws/testsuite/installation.html"),
{skip, "Autobahn Test Suite not installed."};
_ ->
- {ok, _} = cowboy:start_http(autobahn, 100, [{port, 33080}], [
+ {ok, _} = cowboy:start_http(Name, 100, [{port, 33080}], [
{env, [{dispatch, init_dispatch()}]}]),
Config
end;
-init_per_group(ws, Config) ->
- cowboy:start_http(ws, 100, [{port, 0}], [
+init_per_group(Name = ws, Config) ->
+ cowboy_test:init_http(Name, [
{env, [{dispatch, init_dispatch()}]},
{compress, true}
- ]),
- Port = ranch:get_port(ws),
- [{port, Port}|Config].
+ ], Config).
end_per_group(Listener, _Config) ->
- cowboy:stop_listener(Listener),
- ok.
+ cowboy:stop_listener(Listener).
%% Dispatch configuration.