aboutsummaryrefslogtreecommitdiffstats
path: root/test/acceptor_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'test/acceptor_SUITE.erl')
-rw-r--r--test/acceptor_SUITE.erl61
1 files changed, 54 insertions, 7 deletions
diff --git a/test/acceptor_SUITE.erl b/test/acceptor_SUITE.erl
index 0a15916..bf74a1d 100644
--- a/test/acceptor_SUITE.erl
+++ b/test/acceptor_SUITE.erl
@@ -16,17 +16,31 @@
-include_lib("common_test/include/ct.hrl").
--export([all/0, groups/0, init_per_suite/1, end_per_suite/1]). %% ct.
--export([tcp_echo/1]). %% tcp.
+%% ct.
+-export([all/0]).
+-export([groups/0]).
+-export([init_per_suite/1]).
+-export([end_per_suite/1]).
+-export([init_per_group/2]).
+-export([end_per_group/2]).
+
+%% ssl.
+-export([ssl_echo/1]).
+
+%% tcp.
+-export([tcp_echo/1]).
%% ct.
all() ->
- [{group, tcp}].
+ [{group, tcp}, {group, ssl}].
groups() ->
- Tests = [tcp_echo],
- [{tcp, Tests}].
+ [{tcp, [
+ tcp_echo
+ ]}, {ssl, [
+ ssl_echo
+ ]}].
init_per_suite(Config) ->
application:start(ranch),
@@ -36,6 +50,39 @@ end_per_suite(_) ->
application:stop(ranch),
ok.
+init_per_group(ssl, Config) ->
+ application:start(crypto),
+ application:start(public_key),
+ application:start(ssl),
+ Config;
+init_per_group(_, Config) ->
+ Config.
+
+end_per_group(ssl, _) ->
+ application:stop(ssl),
+ application:stop(public_key),
+ application:stop(crypto),
+ ok;
+end_per_group(_, _) ->
+ ok.
+
+%% ssl.
+
+ssl_echo(Config) ->
+ {ok, _} = ranch:start_listener(ssl_echo, 1,
+ ranch_ssl, [{port, 0},
+ {certfile, ?config(data_dir, Config) ++ "cert.pem"}],
+ echo_protocol, []),
+ Port = ranch:get_port(ssl_echo),
+ {ok, Socket} = ssl:connect("localhost", Port,
+ [binary, {active, false}, {packet, raw},
+ {certfile, ?config(data_dir, Config) ++ "cert.pem"}]),
+ ok = ssl:send(Socket, <<"SSL Ranch is working!">>),
+ {ok, <<"SSL Ranch is working!">>} = ssl:recv(Socket, 21, 1000),
+ ok = ranch:stop_listener(ssl_echo),
+ {error, closed} = ssl:recv(Socket, 0, 1000),
+ ok.
+
%% tcp.
tcp_echo(_) ->
@@ -44,8 +91,8 @@ tcp_echo(_) ->
Port = ranch:get_port(tcp_echo),
{ok, Socket} = gen_tcp:connect("localhost", Port,
[binary, {active, false}, {packet, raw}]),
- ok = gen_tcp:send(Socket, <<"Ranch is working!">>),
- {ok, <<"Ranch is working!">>} = gen_tcp:recv(Socket, 0, 1000),
+ ok = gen_tcp:send(Socket, <<"TCP Ranch is working!">>),
+ {ok, <<"TCP Ranch is working!">>} = gen_tcp:recv(Socket, 21, 1000),
ok = ranch:stop_listener(tcp_echo),
{error, closed} = gen_tcp:recv(Socket, 0, 1000),
ok.