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/5c5bfce9 Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/5c5bfce9 Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/5c5bfce9 Branch: refs/heads/1.x.x Commit: 5c5bfce9a0eccd2ca3c686a3025f76922cf45d50 Parents: 39c37ec Author: Alexander Shorin <[email protected]> Authored: Fri May 23 09:29:22 2014 +0400 Committer: Alexander Shorin <[email protected]> Committed: Wed Dec 2 03:49:04 2015 +0300 ---------------------------------------------------------------------- test/couchdb/Makefile.am | 1 + test/couchdb/couch_config_tests.erl | 165 +++++++++++++++++++++++++++++++ test/etap/080-config-get-set.t | 128 ------------------------ test/etap/Makefile.am | 1 - 4 files changed, 166 insertions(+), 129 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb/blob/5c5bfce9/test/couchdb/Makefile.am ---------------------------------------------------------------------- diff --git a/test/couchdb/Makefile.am b/test/couchdb/Makefile.am index b2f9ebc..5070cc3 100644 --- a/test/couchdb/Makefile.am +++ b/test/couchdb/Makefile.am @@ -24,6 +24,7 @@ eunit_files = \ couch_auth_cache_tests.erl \ couch_btree_tests.erl \ couch_changes_tests.erl \ + couch_config_tests.erl \ couch_db_tests.erl \ couch_doc_json_tests.erl \ couch_file_tests.erl \ http://git-wip-us.apache.org/repos/asf/couchdb/blob/5c5bfce9/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..ecff590 --- /dev/null +++ b/test/couchdb/couch_config_tests.erl @@ -0,0 +1,165 @@ +% 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("couch_eunit.hrl"). +-include_lib("couchdb/couch_db.hrl"). + +-define(TIMEOUT, 1000). + + +setup() -> + {ok, Pid} = couch_config:start_link(?CONFIG_CHAIN), + Pid. + +teardown(Pid) -> + couch_config:stop(), + erlang:monitor(process, Pid), + receive + {'DOWN', _, _, Pid, _} -> + ok + after ?TIMEOUT -> + 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/5c5bfce9/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/5c5bfce9/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 \
