aboutsummaryrefslogtreecommitdiffstats
path: root/test/examples_SUITE.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2016-06-09 16:33:31 +0200
committerLoïc Hoguin <[email protected]>2016-06-09 16:33:31 +0200
commit4293a40d9e922bc00f25d6c7e328f86e102275a0 (patch)
treec8d46b36acf08fbf06990bf7cf6f67f26c28f3cf /test/examples_SUITE.erl
parent5ca49fefa9006f4e9c853adf69da93f6f6bdf7bd (diff)
downloadcowboy-4293a40d9e922bc00f25d6c7e328f86e102275a0.tar.gz
cowboy-4293a40d9e922bc00f25d6c7e328f86e102275a0.tar.bz2
cowboy-4293a40d9e922bc00f25d6c7e328f86e102275a0.zip
Fix rest_hello_world example
Diffstat (limited to 'test/examples_SUITE.erl')
-rw-r--r--test/examples_SUITE.erl42
1 files changed, 41 insertions, 1 deletions
diff --git a/test/examples_SUITE.erl b/test/examples_SUITE.erl
index fb95f3b..111e118 100644
--- a/test/examples_SUITE.erl
+++ b/test/examples_SUITE.erl
@@ -93,7 +93,7 @@ do_hello_world(Transport, Protocol, Config) ->
{ok, <<"Hello world!">>} = gun:await_body(ConnPid, Ref),
ok.
-%% Echo GET and POST.
+%% Echo GET.
echo_get(Config) ->
doc("GET parameter echo example."),
@@ -112,6 +112,8 @@ do_echo_get(Transport, Protocol, Config) ->
{ok, <<"this is fun">>} = gun:await_body(ConnPid, Ref),
ok.
+%% Echo POST.
+
echo_post(Config) ->
doc("POST parameter echo example."),
try
@@ -130,3 +132,41 @@ do_echo_post(Transport, Protocol, Config) ->
{response, nofin, 200, _} = gun:await(ConnPid, Ref),
{ok, <<"this is fun">>} = gun:await_body(ConnPid, Ref),
ok.
+
+%% REST Hello World.
+
+rest_hello_world(Config) ->
+ doc("REST Hello World example."),
+ try
+ do_compile_and_start(rest_hello_world),
+ do_rest_hello_world(tcp, http, Config),
+ do_rest_hello_world(tcp, http2, Config)
+ after
+ do_stop(rest_hello_world)
+ end.
+
+do_rest_hello_world(Transport, Protocol, Config) ->
+ << "<html>", _/bits >> = do_rest_hello_world_get(Transport, Protocol, undefined, Config),
+ << "REST Hello World as text!" >> = do_rest_hello_world_get(Transport, Protocol, <<"text/plain">>, Config),
+ << "{\"rest\": \"Hello World!\"}" >> = do_rest_hello_world_get(Transport, Protocol, <<"application/json">>, Config),
+ not_acceptable = do_rest_hello_world_get(Transport, Protocol, <<"text/css">>, Config),
+ ok.
+
+do_rest_hello_world_get(Transport, Protocol, Accept, Config) ->
+ Port = case Transport of
+ tcp -> 8080;
+ ssl -> 8443
+ end,
+ ConnPid = gun_open([{port, Port}, {type, Transport}, {protocol, Protocol}|Config]),
+ Headers = case Accept of
+ undefined -> [];
+ _ -> [{<<"accept">>, Accept}]
+ end,
+ Ref = gun:get(ConnPid, "/", Headers),
+ case gun:await(ConnPid, Ref) of
+ {response, nofin, 200, _} ->
+ {ok, Body} = gun:await_body(ConnPid, Ref),
+ Body;
+ {response, _, 406, _} ->
+ not_acceptable
+ end.