Repository: couchdb-config Updated Branches: refs/heads/2708-stronger-testing-for-config-set [created] ee652d2ee
strong testing for config:set calls Closes COUCHDB-2708. This is a cherry-pick of: https://github.com/cloudant/config/commit/d48a2bfdaa7c7c1e0004835c42e98d6794050317 Conflicts: src/config.erl Project: http://git-wip-us.apache.org/repos/asf/couchdb-config/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-config/commit/f695b782 Tree: http://git-wip-us.apache.org/repos/asf/couchdb-config/tree/f695b782 Diff: http://git-wip-us.apache.org/repos/asf/couchdb-config/diff/f695b782 Branch: refs/heads/2708-stronger-testing-for-config-set Commit: f695b782f563de65913e8cd9d7a2597ef395369e Parents: b281825 Author: Robert Newson <rnew...@apache.org> Authored: Fri Nov 7 17:47:12 2014 +0000 Committer: Mike Wallace <mikewall...@apache.org> Committed: Wed Jun 3 12:36:41 2015 +0100 ---------------------------------------------------------------------- src/config.erl | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-config/blob/f695b782/src/config.erl ---------------------------------------------------------------------- diff --git a/src/config.erl b/src/config.erl index a24bb27..301d4e1 100644 --- a/src/config.erl +++ b/src/config.erl @@ -158,8 +158,11 @@ set(Section, Key, Value, Reason) -> set(Sec, Key, Val, Persist, Reason) when is_binary(Sec) and is_binary(Key) -> ?MODULE:set(binary_to_list(Sec), binary_to_list(Key), Val, Persist, Reason); -set(Section, Key, Value, Persist, Reason) - when is_list(Section), is_list(Key), is_list(Value) -> +set(Section, Key, Value, Persist, Reason) when is_boolean(Persist) -> + assert_string(Section), + assert_string(Key), + assert_string(Value), + if Reason == nil -> ok; true -> assert_string(Reason) end, gen_server:call(?MODULE, {set, Section, Key, Value, Persist, Reason}); set(_Sec, _Key, _Val, _Persist, _Reason) -> error(badarg). @@ -177,9 +180,19 @@ delete(Section, Key, Reason) -> delete(Sec, Key, Persist, Reason) when is_binary(Sec) and is_binary(Key) -> delete(binary_to_list(Sec), binary_to_list(Key), Persist, Reason); -delete(Section, Key, Persist, Reason) when is_list(Section), is_list(Key) -> +delete(Section, Key, Persist, Reason) when is_boolean(Persist) -> + assert_string(Section), + assert_string(Key), + if Reason == nil -> ok; true -> assert_string(Reason) end, gen_server:call(?MODULE, {delete, Section, Key, Persist, Reason}). +assert_string(Term) -> + case io_lib:printable_list(Term) of + true -> + ok; + false -> + error(badarg) + end. listen_for_changes(CallbackModule, InitialState) -> gen_server:call(?MODULE, {listen_for_changes, CallbackModule, InitialState}).