You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by mi...@apache.org on 2015/06/03 13:37:52 UTC

[1/3] config commit: updated refs/heads/2708-stronger-testing-for-config-set to ee652d2

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 <rn...@apache.org>
Authored: Fri Nov 7 17:47:12 2014 +0000
Committer: Mike Wallace <mi...@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}).


[3/3] config commit: updated refs/heads/2708-stronger-testing-for-config-set to ee652d2

Posted by mi...@apache.org.
[squash] apply stronger testing to config:get/3


Project: http://git-wip-us.apache.org/repos/asf/couchdb-config/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-config/commit/ee652d2e
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-config/tree/ee652d2e
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-config/diff/ee652d2e

Branch: refs/heads/2708-stronger-testing-for-config-set
Commit: ee652d2ee00ab5b9afea28c2a2a529e4eacf4195
Parents: 6566dd4
Author: Mike Wallace <mi...@apache.org>
Authored: Wed Jun 3 12:23:20 2015 +0100
Committer: Mike Wallace <mi...@apache.org>
Committed: Wed Jun 3 12:37:03 2015 +0100

----------------------------------------------------------------------
 src/config.erl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-config/blob/ee652d2e/src/config.erl
----------------------------------------------------------------------
diff --git a/src/config.erl b/src/config.erl
index 301d4e1..908dee7 100644
--- a/src/config.erl
+++ b/src/config.erl
@@ -137,7 +137,9 @@ get(Section, Key) ->
 
 get(Section, Key, Default) when is_binary(Section) and is_binary(Key) ->
     ?MODULE:get(binary_to_list(Section), binary_to_list(Key), Default);
-get(Section, Key, Default) when is_list(Section), is_list(Key) ->
+get(Section, Key, Default) ->
+    assert_string(Section),
+    assert_string(Key),
     case ets:lookup(?MODULE, {Section, Key}) of
         [] when Default == undefined -> Default;
         [] when is_boolean(Default) -> Default;


[2/3] config commit: updated refs/heads/2708-stronger-testing-for-config-set to ee652d2

Posted by mi...@apache.org.
[squash] Add tests for add stronger config set/get/delete testing


Project: http://git-wip-us.apache.org/repos/asf/couchdb-config/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-config/commit/6566dd43
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-config/tree/6566dd43
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-config/diff/6566dd43

Branch: refs/heads/2708-stronger-testing-for-config-set
Commit: 6566dd43c6f2a6bc8c5c737be2c41477833a3065
Parents: f695b78
Author: Mike Wallace <mi...@apache.org>
Authored: Wed Jun 3 12:16:58 2015 +0100
Committer: Mike Wallace <mi...@apache.org>
Committed: Wed Jun 3 12:37:03 2015 +0100

----------------------------------------------------------------------
 test/config_tests.erl | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-config/blob/6566dd43/test/config_tests.erl
----------------------------------------------------------------------
diff --git a/test/config_tests.erl b/test/config_tests.erl
index c823d3e..778e383 100644
--- a/test/config_tests.erl
+++ b/test/config_tests.erl
@@ -116,7 +116,7 @@ config_get_tests() ->
                 should_return_undefined_atom_on_missed_option(),
                 should_return_custom_default_value_on_missed_option(),
                 should_only_return_default_on_missed_option(),
-                should_fail_to_get_binary_value(),
+                should_fail_to_get_non_string_value(),
                 should_return_any_supported_default()
             ]
         }
@@ -131,7 +131,7 @@ config_set_tests() ->
             [
                 should_update_option(),
                 should_create_new_section(),
-                should_fail_to_set_binary_value()
+                should_fail_to_set_non_string_value()
             ]
         }
     }.
@@ -144,7 +144,8 @@ config_del_tests() ->
             fun setup/0, fun teardown/1,
             [
                 should_return_undefined_atom_after_option_deletion(),
-                should_be_ok_on_deleting_unknown_options()
+                should_be_ok_on_deleting_unknown_options(),
+                should_fail_to_delete_non_string_value()
             ]
         }
     }.
@@ -243,9 +244,11 @@ should_only_return_default_on_missed_option() ->
     ?_assertEqual("0",
                   config:get("httpd", "port", "bar")).
 
-should_fail_to_get_binary_value() ->
+should_fail_to_get_non_string_value() ->
     ?_assertException(error, badarg,
-                  config:get(<<"foo">>, <<"bar">>, <<"baz">>)).
+                  config:get(<<"foo">>, <<"bar">>, <<"baz">>)),
+    ?_assertException(error, badarg,
+                  config:get([f, o, o], [b, a, r], [b, a, z])).
 
 should_return_any_supported_default() ->
     Values = [undefined, "list", true, false, 0.1, 1],
@@ -269,9 +272,11 @@ should_create_new_section() ->
             config:get("new_section", "bizzle")
         end).
 
-should_fail_to_set_binary_value() ->
+should_fail_to_set_non_string_value() ->
+    ?_assertException(error, badarg,
+        config:set(<<"foo">>, <<"bar">>, <<"baz">>, false)),
     ?_assertException(error, badarg,
-        config:set(<<"foo">>, <<"bar">>, <<"baz">>, false)).
+        config:set([f, o, o], [b, a, r], [b, a, z], false)).
 
 should_return_undefined_atom_after_option_deletion() ->
     ?_assertEqual(undefined,
@@ -283,6 +288,12 @@ should_return_undefined_atom_after_option_deletion() ->
 should_be_ok_on_deleting_unknown_options() ->
     ?_assertEqual(ok, config:delete("zoo", "boo", false)).
 
+should_fail_to_delete_non_string_value() ->
+    ?_assertException(error, badarg,
+        config:delete(<<"foo">>, <<"bar">>, false)),
+    ?_assertException(error, badarg,
+        config:delete([f, o, o], [b, a, r], false)).
+
 should_ensure_in_defaults(_, _) ->
     ?_test(begin
         ?assertEqual("500",