Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure all config get's throw on no ets table #4894

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/chttpd/src/chttpd_db.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2609,7 +2609,10 @@ parse_shards_opt_test_() ->
}.

setup() ->
meck:expect(config, get, fun(_, _, Default) -> Default end),
test_util:mock(config),
meck:expect(config, get_boolean, fun(_, _, Default) -> Default end),
meck:expect(config, get_float, fun(_, _, Default) -> Default end),
meck:expect(config, get_integer, fun(_, _, Default) -> Default end),
ok.

teardown(_) ->
Expand Down
3 changes: 2 additions & 1 deletion src/chttpd/src/chttpd_view.erl
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ setup_all() ->
meck:expect(chttpd, start_delayed_json_response, 4, {ok, resp}),
meck:expect(fabric, query_view, 7, {ok, #vacc{}}),
meck:expect(chttpd, send_delayed_chunk, 2, {ok, resp}),
meck:expect(chttpd, end_delayed_json_response, 1, ok).
meck:expect(chttpd, end_delayed_json_response, 1, ok),
test_util:mock(config).

teardown_all(_) ->
meck:unload().
Expand Down
9 changes: 6 additions & 3 deletions src/config/src/config.erl
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ all() ->
lists:sort(gen_server:call(?MODULE, all, infinity)).

get_integer(Section, Key, Default) when is_integer(Default) ->
Val = get(Section, Key, Default),
try
to_integer(get(Section, Key, Default))
to_integer(Val)
catch
error:badarg ->
Default
Expand All @@ -91,8 +92,9 @@ to_integer(Bin) when is_binary(Bin) ->
list_to_integer(binary_to_list(Bin)).

get_float(Section, Key, Default) when is_float(Default) ->
Val = get(Section, Key, Default),
try
to_float(get(Section, Key, Default))
to_float(Val)
catch
error:badarg ->
Default
Expand All @@ -116,8 +118,9 @@ to_float(Bin) when is_binary(Bin) ->
list_to_float(binary_to_list(Bin)).

get_boolean(Section, Key, Default) when is_boolean(Default) ->
Val = get(Section, Key, Default),
try
to_boolean(get(Section, Key, Default))
to_boolean(Val)
catch
error:badarg ->
Default
Expand Down
2 changes: 1 addition & 1 deletion src/couch/src/couch_db.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2395,7 +2395,7 @@ setup_purge_seq() ->
meck:new(couch_log, [passthrough]),
meck:new(config, [passthrough]),
meck:new(couch_db_plugin, [passthrough]),
meck:expect(config, get, fun(_, _, Default) -> Default end),
test_util:mock(config),
ok.

teardown_purge_seq(_) ->
Expand Down
2 changes: 1 addition & 1 deletion src/couch/src/couch_query_servers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ db_key_test_() ->

setup() ->
meck:new(config, [passthrough]),
meck:expect(config, get, fun(_, _, Default) -> Default end),
test_util:mock(config),
ok.

teardown(_) ->
Expand Down
7 changes: 6 additions & 1 deletion src/couch/src/test_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

-export([as_selector/1]).

-export([mock/1]).

-include_lib("couch/include/couch_eunit.hrl").
-include_lib("couch/include/couch_db.hrl").
-include("couch_db_int.hrl").
Expand Down Expand Up @@ -361,7 +363,10 @@ mock(Modules) when is_list(Modules) ->
mock(config) ->
meck:new(config, [passthrough]),
meck:expect(config, get, fun(_, _) -> undefined end),
meck:expect(config, get, fun(_, _, Default) -> Default end),
test_util:mock(config),
meck:expect(config, get_boolean, fun(_, _, Default) -> Default end),
meck:expect(config, get_float, fun(_, _, Default) -> Default end),
meck:expect(config, get_integer, fun(_, _, Default) -> Default end),
ok;
mock(couch_stats) ->
meck:new(couch_stats, [passthrough]),
Expand Down
2 changes: 1 addition & 1 deletion src/couch_replicator/src/couch_replicator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ strip_url_creds_test_() ->
{
setup,
fun() ->
meck:expect(config, get, fun(_, _, Default) -> Default end)
test_util:mock(config)
end,
fun(_) ->
meck:unload()
Expand Down
2 changes: 1 addition & 1 deletion src/couch_replicator/src/couch_replicator_auth_session.erl
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ httpdb(Url) ->
setup_all() ->
meck:expect(couch_replicator_httpc_pool, get_worker, 1, {ok, worker}),
meck:expect(couch_replicator_httpc_pool, release_worker_sync, 2, ok),
meck:expect(config, get, fun(_, _, Default) -> Default end),
test_util:mock(config),
mock_http_cookie_response("Abc"),
ok.

Expand Down
2 changes: 1 addition & 1 deletion src/couch_replicator/src/couch_replicator_clustering.erl
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ t_unstable_callback() ->

setup_all() ->
meck:expect(couch_log, notice, 2, ok),
meck:expect(config, get, fun(_, _, Default) -> Default end),
test_util:mock(config),
meck:expect(config, listen_for_changes, 2, ok),
meck:expect(couch_stats, update_gauge, 2, ok),
meck:expect(couch_replicator_notifier, notify, 1, ok).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ setup_all() ->
meck:expect(couch_log, notice, 2, ok),
meck:expect(couch_log, warning, 2, ok),
meck:expect(couch_log, error, 2, ok),
meck:expect(config, get, fun(_, _, Default) -> Default end),
test_util:mock(config),
meck:expect(config, listen_for_changes, 2, ok),
meck:expect(couch_replicator_clustering, owner, 2, node()),
meck:expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ t_ignore_if_worker_ref_does_not_match() ->

setup() ->
meck:expect(couch_replicator_scheduler, add_job, 1, ok),
meck:expect(config, get, fun(_, _, Default) -> Default end),
test_util:mock(config),
meck:expect(couch_server, get_uuid, 0, this_is_snek),
meck:expect(couch_replicator_docs, update_failed, 3, ok),
meck:expect(couch_replicator_scheduler, rep_state, 1, nil),
Expand Down
2 changes: 1 addition & 1 deletion src/couch_replicator/src/couch_replicator_parse.erl
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ local_replication_endpoint_error_test_() ->
}.

meck_config() ->
meck:expect(config, get, fun(_, _, Default) -> Default end).
test_util:mock(config).

t_error_on_local_endpoint(_) ->
RepDoc =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ format_status_test_() ->
}.

meck_config() ->
meck:expect(config, get, fun(_, _, Default) -> Default end).
test_util:mock(config).

t_scheduler_job_format_status(_) ->
Source = <<"http://u:p@h1/d1">>,
Expand Down
2 changes: 1 addition & 1 deletion src/smoosh/src/smoosh_persist.erl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ persist_unpersist_test_() ->
{
foreach,
fun() ->
meck:expect(config, get, fun(_, _, Default) -> Default end)
test_util:mock(config)
end,
fun(_) ->
meck:unload()
Expand Down
4 changes: 2 additions & 2 deletions src/smoosh/src/smoosh_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -569,13 +569,13 @@ setup_all() ->
Ctx = setup_all_no_mock(),
Pid = list_to_pid("<0.0.0>"),
meck:expect(couch_index_server, get_index, 3, {ok, Pid}),
meck:expect(config, get, fun(_, _, Default) -> Default end),
test_util:mock(config),
Ctx.

setup_all_no_mock() ->
Ctx = test_util:start_couch([couch_log]),
meck:new([config, couch_index, couch_index_server], [passthrough]),
meck:expect(config, get, fun(_, _, Default) -> Default end),
test_util:mock(config),
Ctx.

teardown_all(Ctx) ->
Expand Down
2 changes: 1 addition & 1 deletion src/smoosh/src/smoosh_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ smoosh_utils_test_() ->
foreach,
fun() ->
meck:new(calendar, [passthrough, unstick]),
meck:expect(config, get, fun(_, _, Default) -> Default end)
test_util:mock(config)
end,
fun(_) ->
meck:unload()
Expand Down