Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 427B510176 for ; Mon, 1 Dec 2014 20:22:14 +0000 (UTC) Received: (qmail 74933 invoked by uid 500); 1 Dec 2014 20:22:14 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 74881 invoked by uid 500); 1 Dec 2014 20:22:14 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 74872 invoked by uid 99); 1 Dec 2014 20:22:14 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Dec 2014 20:22:14 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id CAB529B4442; Mon, 1 Dec 2014 20:22:13 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: robertkowalski@apache.org To: commits@couchdb.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: couch commit: updated refs/heads/master to 2a45cb0 Date: Mon, 1 Dec 2014 20:22:13 +0000 (UTC) Repository: couchdb-couch Updated Branches: refs/heads/master 741a82d4c -> 2a45cb032 Expose and add helper for tests In order to make them reusable in the chhtpd integration-tests. Additionally adding a post and delete helper. COUCHDB-2462 Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/2a45cb03 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/2a45cb03 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/2a45cb03 Branch: refs/heads/master Commit: 2a45cb0325b72eb0910029bed5d2c38f784f68f9 Parents: 741a82d Author: Robert Kowalski Authored: Sun Nov 30 03:13:36 2014 +0100 Committer: Robert Kowalski Committed: Mon Dec 1 21:22:43 2014 +0100 ---------------------------------------------------------------------- src/test_request.erl | 81 ++++++++++++++++++++++++++++++++++++++++++++++ src/test_util.erl | 1 + test/test_request.erl | 75 ------------------------------------------ 3 files changed, 82 insertions(+), 75 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/2a45cb03/src/test_request.erl ---------------------------------------------------------------------- diff --git a/src/test_request.erl b/src/test_request.erl new file mode 100644 index 0000000..9693976 --- /dev/null +++ b/src/test_request.erl @@ -0,0 +1,81 @@ +% Licensed under the Apache License, Version 2.0 (the "License"); you may not +% use this file except in compliance with the License. You may obtain a copy of +% the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +% License for the specific language governing permissions and limitations under +% the License. + +-module(test_request). + +-export([get/1, get/2, get/3]). +-export([post/3]). +-export([put/2, put/3]). +-export([delete/1]). +-export([options/1, options/2, options/3]). +-export([request/3, request/4]). + +get(Url) -> + request(get, Url, []). + +get(Url, Headers) -> + request(get, Url, Headers). +get(Url, Headers, Opts) -> + request(get, Url, Headers, [], Opts). + +post(Url, Headers, Body) -> + request(post, Url, Headers, Body). + +put(Url, Body) -> + request(put, Url, [], Body). + +put(Url, Headers, Body) -> + request(put, Url, Headers, Body). + +delete(Url) -> + request(delete, Url, []). + +options(Url) -> + request(options, Url, []). + +options(Url, Headers) -> + request(options, Url, Headers). + +options(Url, Headers, Opts) -> + request(options, Url, Headers, [], Opts). + + +request(Method, Url, Headers) -> + request(Method, Url, Headers, []). + +request(Method, Url, Headers, Body) -> + request(Method, Url, Headers, Body, [], 3). + +request(Method, Url, Headers, Body, Opts) -> + request(Method, Url, Headers, Body, Opts, 3). + +request(_Method, _Url, _Headers, _Body, _Opts, 0) -> + {error, request_failed}; +request(Method, Url, Headers, Body, Opts, N) -> + case code:is_loaded(ibrowse) of + false -> + {ok, _} = ibrowse:start(); + _ -> + ok + end, + case ibrowse:send_req(Url, Headers, Method, Body, Opts) of + {ok, Code0, RespHeaders, RespBody0} -> + Code = list_to_integer(Code0), + RespBody = iolist_to_binary(RespBody0), + {ok, Code, RespHeaders, RespBody}; + {error, {'EXIT', {normal, _}}} -> + % Connection closed right after a successful request that + % used the same connection. + request(Method, Url, Headers, Body, N - 1); + Error -> + Error + end. http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/2a45cb03/src/test_util.erl ---------------------------------------------------------------------- diff --git a/src/test_util.erl b/src/test_util.erl index 3f90330..9340d36 100644 --- a/src/test_util.erl +++ b/src/test_util.erl @@ -20,6 +20,7 @@ -export([request/3, request/4]). -export([start_couch/0, start_couch/1, stop_couch/0, stop_couch/1]). -export([start_config/1, stop_config/1]). +-export([start_applications/1]). srcdir() -> http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/2a45cb03/test/test_request.erl ---------------------------------------------------------------------- diff --git a/test/test_request.erl b/test/test_request.erl deleted file mode 100644 index 68e4956..0000000 --- a/test/test_request.erl +++ /dev/null @@ -1,75 +0,0 @@ -% Licensed under the Apache License, Version 2.0 (the "License"); you may not -% use this file except in compliance with the License. You may obtain a copy of -% the License at -% -% http://www.apache.org/licenses/LICENSE-2.0 -% -% Unless required by applicable law or agreed to in writing, software -% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -% License for the specific language governing permissions and limitations under -% the License. - --module(test_request). - --export([get/1, get/2, get/3]). --export([put/2, put/3]). --export([options/1, options/2, options/3]). --export([request/3, request/4]). - -get(Url) -> - request(get, Url, []). - -get(Url, Headers) -> - request(get, Url, Headers). -get(Url, Headers, Opts) -> - request(get, Url, Headers, [], Opts). - - -put(Url, Body) -> - request(put, Url, [], Body). - -put(Url, Headers, Body) -> - request(put, Url, Headers, Body). - - -options(Url) -> - request(options, Url, []). - -options(Url, Headers) -> - request(options, Url, Headers). - -options(Url, Headers, Opts) -> - request(options, Url, Headers, [], Opts). - - -request(Method, Url, Headers) -> - request(Method, Url, Headers, []). - -request(Method, Url, Headers, Body) -> - request(Method, Url, Headers, Body, [], 3). - -request(Method, Url, Headers, Body, Opts) -> - request(Method, Url, Headers, Body, Opts, 3). - -request(_Method, _Url, _Headers, _Body, _Opts, 0) -> - {error, request_failed}; -request(Method, Url, Headers, Body, Opts, N) -> - case code:is_loaded(ibrowse) of - false -> - {ok, _} = ibrowse:start(); - _ -> - ok - end, - case ibrowse:send_req(Url, Headers, Method, Body, Opts) of - {ok, Code0, RespHeaders, RespBody0} -> - Code = list_to_integer(Code0), - RespBody = iolist_to_binary(RespBody0), - {ok, Code, RespHeaders, RespBody}; - {error, {'EXIT', {normal, _}}} -> - % Connection closed right after a successful request that - % used the same connection. - request(Method, Url, Headers, Body, N - 1); - Error -> - Error - end.