From 8dde7dbc425cac5a58e10e68649a109a57a1f1bf Mon Sep 17 00:00:00 2001 From: ILYA Khlopotov Date: Tue, 25 Aug 2015 09:49:51 -0700 Subject: [PATCH 1/2] Add test suite for http endpoints COUCHDB-2789 --- test/mango_httpd_handlers_tests.erl | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 test/mango_httpd_handlers_tests.erl diff --git a/test/mango_httpd_handlers_tests.erl b/test/mango_httpd_handlers_tests.erl new file mode 100644 index 0000000..8c9e705 --- /dev/null +++ b/test/mango_httpd_handlers_tests.erl @@ -0,0 +1,32 @@ +% 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(mango_httpd_handlers_tests). + +-export([handlers/1]). + +-include_lib("couch/include/couch_eunit.hrl"). + +handlers(url_handler) -> + []; +handlers(db_handler) -> + [ + {<<"_index">>, mango_httpd, handle_req}, + {<<"_explain">>, mango_httpd, handle_req}, + {<<"_find">>, mango_httpd, handle_req} + ]; +handlers(design_handler) -> + []. + +mango_endpoints_test_() -> + Apps = [couch_epi, mango], + chttpd_httpd_handlers_test_util:endpoints_test(mango, ?MODULE, Apps). From a94ae7320d68c45c780c733b39b5711f808b4063 Mon Sep 17 00:00:00 2001 From: ILYA Khlopotov Date: Thu, 27 Aug 2015 08:13:55 -0700 Subject: [PATCH 2/2] Add an ability to introspect endpoints and tests COUCHDB-2789 --- src/mango_httpd_handlers.erl | 22 +++++++++++++++++++- test/mango_httpd_handlers_tests.erl | 32 ----------------------------- 2 files changed, 21 insertions(+), 33 deletions(-) delete mode 100644 test/mango_httpd_handlers_tests.erl diff --git a/src/mango_httpd_handlers.erl b/src/mango_httpd_handlers.erl index 80e5e27..311c568 100644 --- a/src/mango_httpd_handlers.erl +++ b/src/mango_httpd_handlers.erl @@ -12,7 +12,7 @@ -module(mango_httpd_handlers). --export([url_handler/1, db_handler/1, design_handler/1]). +-export([url_handler/1, db_handler/1, design_handler/1, endpoints/1]). url_handler(_) -> no_match. @@ -22,3 +22,23 @@ db_handler(<<"_find">>) -> fun mango_httpd:handle_req/2; db_handler(_) -> no_match. design_handler(_) -> no_match. + +endpoints(url_handler) -> + []; +endpoints(db_handler) -> + [ + <<"_index">>, + <<"_explain">>, + <<"_find">> + ]; +endpoints(design_handler) -> + []. + +-ifdef(TEST). +-include_lib("eunit/include/eunit.hrl"). + +mango_endpoints_test_() -> + Apps = [couch_epi, mango], + chttpd_httpd_handlers_test_util:endpoints_test(mango, ?MODULE, Apps). + +-endif. diff --git a/test/mango_httpd_handlers_tests.erl b/test/mango_httpd_handlers_tests.erl deleted file mode 100644 index 8c9e705..0000000 --- a/test/mango_httpd_handlers_tests.erl +++ /dev/null @@ -1,32 +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(mango_httpd_handlers_tests). - --export([handlers/1]). - --include_lib("couch/include/couch_eunit.hrl"). - -handlers(url_handler) -> - []; -handlers(db_handler) -> - [ - {<<"_index">>, mango_httpd, handle_req}, - {<<"_explain">>, mango_httpd, handle_req}, - {<<"_find">>, mango_httpd, handle_req} - ]; -handlers(design_handler) -> - []. - -mango_endpoints_test_() -> - Apps = [couch_epi, mango], - chttpd_httpd_handlers_test_util:endpoints_test(mango, ?MODULE, Apps).