nickva commented on code in PR #4266:
URL: https://github.com/apache/couchdb/pull/4266#discussion_r1026732841


##########
src/smoosh/src/smoosh_utils.erl:
##########
@@ -135,3 +93,196 @@ parse_time(String, Default) ->
 
 log_level(Key, Default) when is_list(Key), is_list(Default) ->
     list_to_existing_atom(config:get("smoosh", Key, Default)).
+
+db_channels() ->
+    ConfStr = config:get("smoosh", "db_channels"),
+    channel_list(ConfStr, ?BUILT_IN_DB_CHANNELS).
+
+view_channels() ->
+    Conf = config:get("smoosh", "view_channels"),
+    channel_list(Conf, ?BUILT_IN_VIEW_CHANNELS).
+
+cleanup_channels() ->
+    Conf = config:get("smoosh", "cleanup_channels"),
+    channel_list(Conf, ?BUILT_IN_CLEANUP_CHANNELS).
+
+channel_list(ConfStr, Default) ->
+    DefaultList = split(Default),
+    ConfList = split(ConfStr),
+    lists:usort(DefaultList ++ ConfList).
+
+concurrency(ChannelName) ->
+    list_to_integer(?MODULE:get(ChannelName, "concurrency", "1")).
+
+capacity(ChannelName) ->
+    list_to_integer(?MODULE:get(ChannelName, "capacity", "9999")).
+
+% Validate enqueue arg at the front of the API instead of adding ?l2b and ?b2l
+% everywhere internally
+%
+validate_arg({?INDEX_CLEANUP, DbName}) when is_list(DbName) ->
+    validate_arg({?INDEX_CLEANUP, ?l2b(DbName)});
+validate_arg(DbName) when is_list(DbName) ->
+    validate_arg(?l2b(DbName));
+validate_arg({DbName, GroupId}) when is_list(DbName) ->
+    validate_arg({?l2b(DbName), GroupId});
+validate_arg({DbName, GroupId}) when is_list(GroupId) ->
+    validate_arg({DbName, ?l2b(GroupId)});
+validate_arg(DbName) when is_binary(DbName) ->
+    DbName;
+validate_arg({DbName, GroupId}) when is_binary(DbName), is_binary(GroupId) ->
+    {DbName, GroupId};
+validate_arg({?INDEX_CLEANUP, DbName}) when is_binary(DbName) ->
+    {?INDEX_CLEANUP, DbName};
+validate_arg(_) ->
+    error(invalid_smoosh_arg).
+
+-ifdef(TEST).
+
+-include_lib("couch/include/couch_eunit.hrl").
+
+smoosh_util_validate_test() ->
+    ?assertEqual(<<"x">>, validate_arg(<<"x">>)),
+    ?assertEqual(<<"x">>, validate_arg("x")),
+    ?assertEqual({<<"x">>, <<"y">>}, validate_arg({"x", "y"})),
+    ?assertEqual({<<"x">>, <<"y">>}, validate_arg({<<"x">>, "y"})),
+    ?assertEqual({<<"x">>, <<"y">>}, validate_arg({"x", <<"y">>})),
+    ?assertEqual({<<"x">>, <<"y">>}, validate_arg({<<"x">>, <<"y">>})),
+    ?assertEqual({?INDEX_CLEANUP, <<"x">>}, validate_arg({?INDEX_CLEANUP, 
"x"})),
+    ?assertEqual({?INDEX_CLEANUP, <<"x">>}, validate_arg({?INDEX_CLEANUP, 
<<"x">>})),
+    ?assertError(invalid_smoosh_arg, validate_arg(foo)),
+    ?assertError(invalid_smoosh_arg, validate_arg({foo, bar})),
+    ?assertError(invalid_smoosh_arg, validate_arg({?INDEX_CLEANUP, foo})).
+
+smoosh_utils_test_() ->
+    {
+        foreach,
+        fun() ->
+            meck:new(calendar, [passthrough, unstick]),
+            meck:expect(config, get, fun(_, _, Default) -> Default end)
+        end,
+        fun(_) ->
+            meck:unload()
+        end,
+        [
+            ?TDEF_FE(t_channel_list_default),
+            ?TDEF_FE(t_channel_list_configured),
+            ?TDEF_FE(t_capacity),
+            ?TDEF_FE(t_concurrency),
+            ?TDEF_FE(t_stringify),
+            ?TDEF_FE(t_ignore_db),
+            ?TDEF_FE(t_log_level),
+            ?TDEF_FE(t_allowed_window)
+        ]
+    }.
+
+t_channel_list_default(_) ->
+    ?assertEqual(
+        ["ratio_dbs", "slack_dbs", "upgrade_dbs"],

Review Comment:
   I thought of making them explicit to make the tests look more uniform and 
also serve as double-check for spelling the defaults correctly.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to