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 CD3341086A for ; Tue, 3 Jun 2014 15:54:41 +0000 (UTC) Received: (qmail 40617 invoked by uid 500); 3 Jun 2014 15:54:40 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 40466 invoked by uid 500); 3 Jun 2014 15:54:40 -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 40056 invoked by uid 99); 3 Jun 2014 15:54:40 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Jun 2014 15:54:40 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 28E3E942544; Tue, 3 Jun 2014 15:54:40 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: kxepal@apache.org To: commits@couchdb.apache.org Date: Tue, 03 Jun 2014 15:54:57 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [19/36] couchdb commit: updated refs/heads/1963-eunit to 85f2750 Port 080-config-get-set.t etap test suite to eunit Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/f90ddf59 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/f90ddf59 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/f90ddf59 Branch: refs/heads/1963-eunit Commit: f90ddf5918f5399a591b1fb427440fb48f707e94 Parents: cfc6f6a Author: Alexander Shorin Authored: Fri May 23 09:29:22 2014 +0400 Committer: Alexander Shorin Committed: Tue Jun 3 15:14:26 2014 +0400 ---------------------------------------------------------------------- test/couchdb/Makefile.am | 1 + test/couchdb/couch_config_tests.erl | 163 +++++++++++++++++++++++++++++++ test/etap/080-config-get-set.t | 128 ------------------------ test/etap/Makefile.am | 1 - 4 files changed, 164 insertions(+), 129 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/f90ddf59/test/couchdb/Makefile.am ---------------------------------------------------------------------- diff --git a/test/couchdb/Makefile.am b/test/couchdb/Makefile.am index b763a0c..8668b96 100644 --- a/test/couchdb/Makefile.am +++ b/test/couchdb/Makefile.am @@ -33,6 +33,7 @@ eunit_files = \ couchdb_update_conflicts_tests.erl \ couch_auth_cache_tests.erl \ couchdb_file_compression_tests.erl \ + couch_config_tests.erl \ test_request.erl \ couchdb_tests.hrl http://git-wip-us.apache.org/repos/asf/couchdb/blob/f90ddf59/test/couchdb/couch_config_tests.erl ---------------------------------------------------------------------- diff --git a/test/couchdb/couch_config_tests.erl b/test/couchdb/couch_config_tests.erl new file mode 100644 index 0000000..9d09640 --- /dev/null +++ b/test/couchdb/couch_config_tests.erl @@ -0,0 +1,163 @@ +% 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(couch_config_tests). + +-include("../../src/couchdb/couch_db.hrl"). +-include("couchdb_tests.hrl"). + + +setup() -> + {ok, Pid} = couch_config:start_link(?CONFIG_CHAIN), + Pid. + +teardown(Pid) -> + couch_config:stop(), + erlang:monitor(process, Pid), + receive + {'DOWN', _, _, Pid, _} -> + ok + after 1000 -> + throw({timeout_error, config_stop}) + end. + + +couch_config_test_() -> + { + "CouchDB config tests", + [ + couch_config_get_tests(), + couch_config_set_tests(), + couch_config_del_tests() + ] + }. + +couch_config_get_tests() -> + { + "Config get tests", + { + foreach, + fun setup/0, fun teardown/1, + [ + should_load_all_configs(), + should_locate_daemons_section(), + should_locate_mrview_handler(), + should_return_undefined_atom_on_missed_section(), + should_return_undefined_atom_on_missed_option(), + should_return_custom_default_value_on_missed_option(), + should_only_return_default_on_missed_option(), + should_get_binary_option() + ] + } + }. + +couch_config_set_tests() -> + { + "Config set tests", + { + foreach, + fun setup/0, fun teardown/1, + [ + should_update_option(), + should_create_new_section(), + should_set_binary_option() + ] + } + }. + +couch_config_del_tests() -> + { + "Config deletion tests", + { + foreach, + fun setup/0, fun teardown/1, + [ + should_return_undefined_atom_after_option_deletion(), + should_be_ok_on_deleting_unknown_options(), + should_delete_binary_option() + ] + } + }. + + +should_load_all_configs() -> + ?_assert(length(couch_config:all()) > 0). + +should_locate_daemons_section() -> + ?_assert(length(couch_config:get("daemons")) > 0). + +should_locate_mrview_handler() -> + ?_assertEqual("{couch_mrview_http, handle_view_req}", + couch_config:get("httpd_design_handlers", "_view")). + +should_return_undefined_atom_on_missed_section() -> + ?_assertEqual(undefined, + couch_config:get("foo", "bar")). + +should_return_undefined_atom_on_missed_option() -> + ?_assertEqual(undefined, + couch_config:get("httpd", "foo")). + +should_return_custom_default_value_on_missed_option() -> + ?_assertEqual("bar", + couch_config:get("httpd", "foo", "bar")). + +should_only_return_default_on_missed_option() -> + ?_assertEqual("0", + couch_config:get("httpd", "port", "bar")). + +should_get_binary_option() -> + ?_assertEqual(<<"baz">>, + couch_config:get(<<"foo">>, <<"bar">>, <<"baz">>)). + +should_update_option() -> + ?_assertEqual("severe", + begin + ok = couch_config:set("log", "level", "severe", false), + couch_config:get("log", "level") + end). + +should_create_new_section() -> + ?_assertEqual("bang", + begin + undefined = couch_config:get("new_section", "bizzle"), + ok = couch_config:set("new_section", "bizzle", "bang", false), + couch_config:get("new_section", "bizzle") + end). + +should_set_binary_option() -> + ?_assertEqual(<<"baz">>, + begin + ok = couch_config:set(<<"foo">>, <<"bar">>, <<"baz">>, false), + couch_config:get(<<"foo">>, <<"bar">>) + end). + +should_return_undefined_atom_after_option_deletion() -> + ?_assertEqual(undefined, + begin + ok = couch_config:delete("log", "level", false), + couch_config:get("log", "level") + end). + +should_be_ok_on_deleting_unknown_options() -> + ?_assertEqual(ok, + begin + couch_config:delete("zoo", "boo", false) + end). + +should_delete_binary_option() -> + ?_assertEqual(undefined, + begin + ok = couch_config:set(<<"foo">>, <<"bar">>, <<"baz">>, false), + ok = couch_config:delete(<<"foo">>, <<"bar">>, false), + couch_config:get(<<"foo">>, <<"bar">>) + end). http://git-wip-us.apache.org/repos/asf/couchdb/blob/f90ddf59/test/etap/080-config-get-set.t ---------------------------------------------------------------------- diff --git a/test/etap/080-config-get-set.t b/test/etap/080-config-get-set.t deleted file mode 100755 index 94a9cba..0000000 --- a/test/etap/080-config-get-set.t +++ /dev/null @@ -1,128 +0,0 @@ -#!/usr/bin/env escript -%% -*- erlang -*- - -% 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. - -default_config() -> - test_util:build_file("etc/couchdb/default_dev.ini"). - -main(_) -> - test_util:init_code_path(), - etap:plan(12), - case (catch test()) of - ok -> - etap:end_tests(); - Other -> - etap:diag(io_lib:format("Test died abnormally: ~p", [Other])), - etap:bail(Other) - end, - ok. - -test() -> - % start couch_config with default - couch_config:start_link([default_config()]), - - - % Check that we can get values - - - etap:fun_is( - fun(List) -> length(List) > 0 end, - couch_config:all(), - "Data was loaded from the INI file." - ), - - etap:fun_is( - fun(List) -> length(List) > 0 end, - couch_config:get("daemons"), - "There are settings in the [daemons] section of the INI file." - ), - - etap:is( - couch_config:get("httpd_design_handlers", "_view"), - "{couch_mrview_http, handle_view_req}", - "The {httpd_design_handlers, view} is the expected default." - ), - - etap:is( - couch_config:get("httpd", "foo", "bar"), - "bar", - "Returns the default when key doesn't exist in config." - ), - - etap:is( - couch_config:get("httpd", "foo"), - undefined, - "The default default is the atom 'undefined'." - ), - - etap:is( - couch_config:get("httpd", "port", "bar"), - "5984", - "Only returns the default when the config setting does not exist." - ), - - - % Check that setting values works. - - - ok = couch_config:set("log", "level", "severe", false), - - etap:is( - couch_config:get("log", "level"), - "severe", - "Non persisted changes take effect." - ), - - etap:is( - couch_config:get("new_section", "bizzle"), - undefined, - "Section 'new_section' does not exist." - ), - - ok = couch_config:set("new_section", "bizzle", "bang", false), - - etap:is( - couch_config:get("new_section", "bizzle"), - "bang", - "New section 'new_section' was created for a new key/value pair." - ), - - - % Check that deleting works - - - ok = couch_config:delete("new_section", "bizzle", false), - etap:is( - couch_config:get("new_section", "bizzle"), - undefined, - "Deleting sets the value to \"\"" - ), - - - % Check ge/set/delete binary strings - - ok = couch_config:set(<<"foo">>, <<"bar">>, <<"baz">>, false), - etap:is( - couch_config:get(<<"foo">>, <<"bar">>), - <<"baz">>, - "Can get and set with binary section and key values." - ), - ok = couch_config:delete(<<"foo">>, <<"bar">>, false), - etap:is( - couch_config:get(<<"foo">>, <<"bar">>), - undefined, - "Deleting with binary section/key pairs sets the value to \"\"" - ), - - ok. http://git-wip-us.apache.org/repos/asf/couchdb/blob/f90ddf59/test/etap/Makefile.am ---------------------------------------------------------------------- diff --git a/test/etap/Makefile.am b/test/etap/Makefile.am index 3d0ad08..436a27b 100644 --- a/test/etap/Makefile.am +++ b/test/etap/Makefile.am @@ -36,7 +36,6 @@ fixture_files = \ fixtures/test.couch tap_files = \ - 080-config-get-set.t \ 081-config-override.1.ini \ 081-config-override.2.ini \ 081-config-override.t \