add some test coverage for #114
Project: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/commit/8bb260f3 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/tree/8bb260f3 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/diff/8bb260f3 Branch: refs/heads/1843-feature-bigcouch Commit: 8bb260f3bf28e05fc46e85ae1345ab40b13df438 Parents: 0f639f6 Author: Bob Ippolito <[email protected]> Authored: Thu Aug 1 14:18:41 2013 -0700 Committer: Bob Ippolito <[email protected]> Committed: Thu Aug 1 14:18:41 2013 -0700 ---------------------------------------------------------------------- CHANGES.md | 3 +++ test/mochiweb_tests.erl | 33 ++++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/8bb260f3/CHANGES.md ---------------------------------------------------------------------- diff --git a/CHANGES.md b/CHANGES.md index 05a71a5..5df6693 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,8 @@ Version 2.7.0 released XXXX-XX-XX +* Add support for all possible `erlang:decode_packet/3` responses, + previously these would just crash. + https://github.com/mochi/mochiweb/pull/114 * Makefile fixed to make `make test` work before `make all` https://github.com/mochi/mochiweb/pull/116 * Usage of the crypto module made R16B01+ compatible http://git-wip-us.apache.org/repos/asf/couchdb-mochiweb/blob/8bb260f3/test/mochiweb_tests.erl ---------------------------------------------------------------------- diff --git a/test/mochiweb_tests.erl b/test/mochiweb_tests.erl index 15cb06a..57587d0 100644 --- a/test/mochiweb_tests.erl +++ b/test/mochiweb_tests.erl @@ -83,8 +83,34 @@ hundred_128_https_POST_test_() -> % note the underscore {timeout, ?LARGE_TIMEOUT, fun() -> ?assertEqual(ok, do_POST(ssl, 128, 100)) end}. +single_GET_relative_test_() -> + [{"ssl", ?_assertEqual(ok, do_GET("derp", ssl, 1))}, + {"plain", ?_assertEqual(ok, do_GET("derp", plain, 1))}]. + +single_CONNECT_test_() -> + [{"ssl", ?_assertEqual(ok, do_CONNECT(ssl, 1))}, + {"plain", ?_assertEqual(ok, do_CONNECT(plain, 1))}]. + +do_CONNECT(Transport, Times) -> + PathPrefix = "example.com:", + ReplyPrefix = "You requested: ", + ServerFun = fun (Req) -> + Reply = ReplyPrefix ++ Req:get(path), + Req:ok({"text/plain", Reply}) + end, + TestReqs = [begin + Path = PathPrefix ++ integer_to_list(N), + ExpectedReply = list_to_binary(ReplyPrefix ++ Path), + #treq{path=Path, xreply=ExpectedReply} + end || N <- lists:seq(1, Times)], + ClientFun = new_client_fun('CONNECT', TestReqs), + ok = with_server(Transport, ServerFun, ClientFun), + ok. + do_GET(Transport, Times) -> - PathPrefix = "/whatever/", + do_GET("/whatever/", Transport, Times). + +do_GET(PathPrefix, Transport, Times) -> ReplyPrefix = "You requested: ", ServerFun = fun (Req) -> Reply = ReplyPrefix ++ Req:get(path), @@ -98,7 +124,6 @@ do_GET(Transport, Times) -> ClientFun = new_client_fun('GET', TestReqs), ok = with_server(Transport, ServerFun, ClientFun), ok. - do_POST(Transport, Size, Times) -> ServerFun = fun (Req) -> Body = Req:recv_body(), @@ -161,7 +186,9 @@ client_request(SockFun, Method, 'GET' -> {ok, {http_response, {1,1}, 200, "OK"}} = SockFun(recv); 'POST' -> - {ok, {http_response, {1,1}, 201, "Created"}} = SockFun(recv) + {ok, {http_response, {1,1}, 201, "Created"}} = SockFun(recv); + 'CONNECT' -> + {ok, {http_response, {1,1}, 200, "OK"}} = SockFun(recv) end, ok = SockFun({setopts, [{packet, httph}]}), {ok, {http_header, _, 'Server', _, "MochiWeb" ++ _}} = SockFun(recv),
