test: update api_config test

This commit is contained in:
Zhongwen Deng 2023-05-09 17:50:16 +08:00
parent 428cc45c69
commit 1d609dacf7
3 changed files with 9 additions and 13 deletions

View File

@ -83,7 +83,7 @@ log.file_handlers {
} }
chars_limit = unlimited chars_limit = unlimited
drop_mode_qlen = 3000 drop_mode_qlen = 3000
enable = false enable = true
file = \"log/my-emqx.log\" file = \"log/my-emqx.log\"
flush_qlen = 8000 flush_qlen = 8000
formatter = text formatter = text

View File

@ -201,8 +201,6 @@ config(put, #{body := NewConf}, Req) ->
case emqx_conf:update(Path, NewConf, ?OPTS) of case emqx_conf:update(Path, NewConf, ?OPTS) of
{ok, #{raw_config := RawConf}} -> {ok, #{raw_config := RawConf}} ->
{200, RawConf}; {200, RawConf};
{error, {permission_denied, Reason}} ->
{403, #{code => 'UPDATE_FAILED', message => Reason}};
{error, Reason} -> {error, Reason} ->
{400, #{code => 'UPDATE_FAILED', message => ?ERR_MSG(Reason)}} {400, #{code => 'UPDATE_FAILED', message => ?ERR_MSG(Reason)}}
end. end.
@ -247,8 +245,6 @@ config_reset(post, _Params, Req) ->
case emqx_conf:reset(Path, ?OPTS) of case emqx_conf:reset(Path, ?OPTS) of
{ok, _} -> {ok, _} ->
{200}; {200};
{error, {permission_denied, Reason}} ->
{403, #{code => 'REST_FAILED', message => Reason}};
{error, no_default_value} -> {error, no_default_value} ->
{400, #{code => 'NO_DEFAULT_VALUE', message => <<"No Default Value.">>}}; {400, #{code => 'NO_DEFAULT_VALUE', message => <<"No Default Value.">>}};
{error, Reason} -> {error, Reason} ->

View File

@ -99,24 +99,24 @@ t_log(_Config) ->
{ok, Log} = get_config("log"), {ok, Log} = get_config("log"),
File = "log/emqx-test.log", File = "log/emqx-test.log",
%% update handler %% update handler
Log1 = emqx_utils_maps:deep_put([<<"file_handlers">>, <<"default">>, <<"enable">>], Log, true), Log1 = emqx_utils_maps:deep_put([<<"file">>, <<"default">>, <<"enable">>], Log, true),
Log2 = emqx_utils_maps:deep_put([<<"file_handlers">>, <<"default">>, <<"file">>], Log1, File), Log2 = emqx_utils_maps:deep_put([<<"file">>, <<"default">>, <<"to">>], Log1, File),
{ok, #{}} = update_config(<<"log">>, Log2), {ok, #{}} = update_config(<<"log">>, Log2),
{ok, Log3} = logger:get_handler_config(default), {ok, Log3} = logger:get_handler_config(default),
?assertMatch(#{config := #{file := File}}, Log3), ?assertMatch(#{config := #{file := File}}, Log3),
ErrLog1 = emqx_utils_maps:deep_put([<<"file_handlers">>, <<"default">>, <<"enable">>], Log, 1), ErrLog1 = emqx_utils_maps:deep_put([<<"file">>, <<"default">>, <<"enable">>], Log, 1),
?assertMatch({error, {"HTTP/1.1", 400, _}}, update_config(<<"log">>, ErrLog1)), ?assertMatch({error, {"HTTP/1.1", 400, _}}, update_config(<<"log">>, ErrLog1)),
ErrLog2 = emqx_utils_maps:deep_put( ErrLog2 = emqx_utils_maps:deep_put(
[<<"file_handlers">>, <<"default">>, <<"enabfe">>], Log, true [<<"file">>, <<"default">>, <<"enabfe">>], Log, true
), ),
?assertMatch({error, {"HTTP/1.1", 400, _}}, update_config(<<"log">>, ErrLog2)), ?assertMatch({error, {"HTTP/1.1", 400, _}}, update_config(<<"log">>, ErrLog2)),
%% add new handler %% add new handler
File1 = "log/emqx-test1.log", File1 = "log/emqx-test1.log",
Handler = emqx_utils_maps:deep_get([<<"file_handlers">>, <<"default">>], Log2), Handler = emqx_utils_maps:deep_get([<<"file">>, <<"default">>], Log2),
NewLog1 = emqx_utils_maps:deep_put([<<"file_handlers">>, <<"new">>], Log2, Handler), NewLog1 = emqx_utils_maps:deep_put([<<"file">>, <<"new">>], Log2, Handler),
NewLog2 = emqx_utils_maps:deep_put( NewLog2 = emqx_utils_maps:deep_put(
[<<"file_handlers">>, <<"new">>, <<"file">>], NewLog1, File1 [<<"file">>, <<"new">>, <<"to">>], NewLog1, File1
), ),
{ok, #{}} = update_config(<<"log">>, NewLog2), {ok, #{}} = update_config(<<"log">>, NewLog2),
{ok, Log4} = logger:get_handler_config(new), {ok, Log4} = logger:get_handler_config(new),
@ -124,7 +124,7 @@ t_log(_Config) ->
%% disable new handler %% disable new handler
Disable = emqx_utils_maps:deep_put( Disable = emqx_utils_maps:deep_put(
[<<"file_handlers">>, <<"new">>, <<"enable">>], NewLog2, false [<<"file">>, <<"new">>, <<"enable">>], NewLog2, false
), ),
{ok, #{}} = update_config(<<"log">>, Disable), {ok, #{}} = update_config(<<"log">>, Disable),
?assertEqual({error, {not_found, new}}, logger:get_handler_config(new)), ?assertEqual({error, {not_found, new}}, logger:get_handler_config(new)),