-
Notifications
You must be signed in to change notification settings - Fork 78
/
Copy pathelli_ssl_tests.erl
62 lines (48 loc) · 1.34 KB
/
elli_ssl_tests.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
-module(elli_ssl_tests).
-include_lib("eunit/include/eunit.hrl").
elli_ssl_test_() ->
{setup,
fun setup/0, fun teardown/1,
[
?_test(hello_world())
]}.
%%
%% TESTS
%%
hello_world() ->
{ok, Response} = httpc:request("https://localhost:3443/hello/world"),
?assertEqual(200, status(Response)).
%%
%% INTERNAL HELPERS
%%
setup() ->
application:start(asn1),
application:start(crypto),
application:start(public_key),
application:start(ssl),
inets:start(),
EbinDir = filename:dirname(code:which(?MODULE)),
CertDir = filename:join([EbinDir, "..", "test"]),
CertFile = filename:join(CertDir, "server_cert.pem"),
KeyFile = filename:join(CertDir, "server_key.pem"),
{ok, P} = elli:start_link([
{port, 3443},
ssl,
{keyfile, KeyFile},
{certfile, CertFile},
{callback, elli_example_callback}
]),
unlink(P),
[P].
teardown(Pids) ->
inets:stop(),
application:stop(ssl),
application:stop(public_key),
application:stop(crypto),
[elli:stop(P) || P <- Pids].
status({{_, Status, _}, _, _}) ->
Status.
body({_, _, Body}) ->
Body.
headers({_, Headers, _}) ->
lists:sort(Headers).