diff options
author | Loïc Hoguin <[email protected]> | 2013-01-29 19:16:45 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2013-01-29 19:16:45 +0100 |
commit | a59c5d6e913e62c0102b4213b0a19a4a403fcf98 (patch) | |
tree | 2de623a1bf0d0ee52f65fc8e724463eb5ebeb800 /test | |
parent | 85d05fff340198bb9af332b7fd503f7c8883e634 (diff) | |
parent | c4d1ee554778cc7c90e0a964bfbdddb8823de0c9 (diff) | |
download | cowboy-a59c5d6e913e62c0102b4213b0a19a4a403fcf98.tar.gz cowboy-a59c5d6e913e62c0102b4213b0a19a4a403fcf98.tar.bz2 cowboy-a59c5d6e913e62c0102b4213b0a19a4a403fcf98.zip |
Merge branch 'rest_patch' of https://github.com/treetopllc/cowboy
Diffstat (limited to 'test')
-rw-r--r-- | test/http_SUITE.erl | 18 | ||||
-rw-r--r-- | test/rest_patch_resource.erl | 34 |
2 files changed, 52 insertions, 0 deletions
diff --git a/test/http_SUITE.erl b/test/http_SUITE.erl index 637bb0d..492863f 100644 --- a/test/http_SUITE.erl +++ b/test/http_SUITE.erl @@ -56,6 +56,7 @@ -export([rest_missing_get_callbacks/1]). -export([rest_missing_put_callbacks/1]). -export([rest_nodelete/1]). +-export([rest_patch/1]). -export([rest_resource_etags/1]). -export([rest_resource_etags_if_none_match/1]). -export([set_resp_body/1]). @@ -117,6 +118,7 @@ groups() -> rest_missing_get_callbacks, rest_missing_put_callbacks, rest_nodelete, + rest_patch, rest_resource_etags, rest_resource_etags_if_none_match, set_resp_body, @@ -331,6 +333,7 @@ init_dispatch(Config) -> {"/missing_get_callbacks", rest_missing_callbacks, []}, {"/missing_put_callbacks", rest_missing_callbacks, []}, {"/nodelete", rest_nodelete_resource, []}, + {"/patch", rest_patch_resource, []}, {"/resetags", rest_resource_etags, []}, {"/rest_expires", rest_expires, []}, {"/loop_timeout", http_handler_loop_timeout, []}, @@ -834,6 +837,21 @@ rest_nodelete(Config) -> build_url("/nodelete", Config), Client), {ok, 500, _, _} = cowboy_client:response(Client2). +rest_patch(Config) -> + Tests = [ + {204, [{<<"content-type">>, <<"text/plain">>}], <<"whatever">>}, + {500, [{<<"content-type">>, <<"text/plain">>}], <<"false">>}, + {400, [{<<"content-type">>, <<"text/plain">>}], <<"halt">>}, + {415, [{<<"content-type">>, <<"application/json">>}], <<"bad_content_type">>} + ], + Client = ?config(client, Config), + _ = [begin + {ok, Client2} = cowboy_client:request(<<"PATCH">>, + build_url("/patch", Config), Headers, Body, Client), + {ok, Status, _, _} = cowboy_client:response(Client2), + ok + end || {Status, Headers, Body} <- Tests]. + rest_resource_get_etag(Config, Type) -> rest_resource_get_etag(Config, Type, []). diff --git a/test/rest_patch_resource.erl b/test/rest_patch_resource.erl new file mode 100644 index 0000000..e265f6f --- /dev/null +++ b/test/rest_patch_resource.erl @@ -0,0 +1,34 @@ +-module(rest_patch_resource). +-export([init/3, allowed_methods/2, content_types_provided/2, get_text_plain/2, + content_types_accepted/2, patch_text_plain/2]). + +init(_Transport, _Req, _Opts) -> + {upgrade, protocol, cowboy_rest}. + +allowed_methods(Req, State) -> + {[<<"HEAD">>, <<"GET">>, <<"PATCH">>], Req, State}. + +content_types_provided(Req, State) -> + {[{{<<"text">>, <<"plain">>, []}, get_text_plain}], Req, State}. + +get_text_plain(Req, State) -> + {<<"This is REST!">>, Req, State}. + +content_types_accepted(Req, State) -> + case cowboy_req:method(Req) of + {<<"PATCH">>, Req0} -> + {[{{<<"text">>, <<"plain">>, []}, patch_text_plain}], Req0, State}; + {_, Req0} -> + {[], Req0, State} + end. + +patch_text_plain(Req, State) -> + case cowboy_req:body(Req) of + {ok, <<"halt">>, Req0} -> + {ok, Req1} = cowboy_req:reply(400, Req0), + {halt, Req1, State}; + {ok, <<"false">>, Req0} -> + {false, Req0, State}; + {ok, _Body, Req0} -> + {true, Req0, State} + end. |