Skip to content

Commit

Permalink
chore(test): improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhuyan committed May 17, 2023
1 parent ea4fbb8 commit 727ad59
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions apps/emqx/src/emqx.erl
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,13 @@ get_config(KeyPath) ->

-spec get_config(emqx_utils_maps:config_key_path(), term()) -> term().
get_config(KeyPath, Default) ->
KeyPath1 = emqx_config:ensure_atom_conf_path(KeyPath, {return, Default}),
emqx_config:get(KeyPath1, Default).
try
KeyPath1 = emqx_config:ensure_atom_conf_path(KeyPath, {raise_error, config_not_found}),
emqx_config:get(KeyPath1, Default)
catch
error:config_not_found ->
Default
end.

-spec get_raw_config(emqx_utils_maps:config_key_path()) -> term().
get_raw_config(KeyPath) ->
Expand Down
13 changes: 13 additions & 0 deletions apps/emqx/test/emqx_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,19 @@ t_cluster_nodes(_) ->
?assertEqual(Expected, emqx:cluster_nodes(cores)),
?assertEqual([], emqx:cluster_nodes(stopped)).

t_get_config(_) ->
?assertEqual(false, emqx:get_config([overload_protection, enable])),
?assertEqual(false, emqx:get_config(["overload_protection", <<"enable">>])).

t_get_config_default_1(_) ->
?assertEqual(false, emqx:get_config([overload_protection, enable], undefined)),
?assertEqual(false, emqx:get_config(["overload_protection", <<"enable">>], undefined)).

t_get_config_default_2(_) ->
AtomPathRes = emqx:get_config([overload_protection, <<"_!no_@exist_">>], undefined),
NonAtomPathRes = emqx:get_config(["doesnotexist", <<"db_backend">>], undefined),
?assertEqual(undefined, NonAtomPathRes),
?assertEqual(undefined, AtomPathRes).
%%--------------------------------------------------------------------
%% Hook fun
%%--------------------------------------------------------------------
Expand Down

0 comments on commit 727ad59

Please sign in to comment.