fix(ctl): fix formatting when printing messages without arguments (4.3)
Without passing an empty argument list to `emqx_ctl:print`, formatting instructions like `~n` are being printed literally. ``` Ignore.~nJoin the cluster successfully.~nCluster status: #{running_nodes => ['emqx@emqx-0.int.thalesmg','emqx@emqx-1.int.thalesmg', 'emqx@emqx-2.int.thalesmg','emqx@emqx-3.int.thalesmg', 'emqx@emqx-4.int.thalesmg'], stopped_nodes => []} ```
This commit is contained in:
parent
ca5c34ba96
commit
b968d4c416
|
@ -302,7 +302,7 @@ t_start_stop_supervised(_Config) ->
|
|||
|
||||
t_acl_cli(_Config) ->
|
||||
meck:new(emqx_ctl, [non_strict, passthrough]),
|
||||
meck:expect(emqx_ctl, print, fun(Arg) -> emqx_ctl:format(Arg) end),
|
||||
meck:expect(emqx_ctl, print, fun(Arg) -> emqx_ctl:format(Arg, []) end),
|
||||
meck:expect(emqx_ctl, print, fun(Msg, Arg) -> emqx_ctl:format(Msg, Arg) end),
|
||||
meck:expect(emqx_ctl, usage, fun(Usages) -> emqx_ctl:format_usage(Usages) end),
|
||||
meck:expect(emqx_ctl, usage, fun(Cmd, Descr) -> emqx_ctl:format_usage(Cmd, Descr) end),
|
||||
|
|
|
@ -158,9 +158,9 @@ t_clients_cmd(_) ->
|
|||
timer:sleep(300),
|
||||
emqx_mgmt_cli:clients(["list"]),
|
||||
?assertMatch({match, _}, re:run(emqx_mgmt_cli:clients(["show", "client12"]), "client12")),
|
||||
?assertEqual("ok~n", emqx_mgmt_cli:clients(["kick", "client12"])),
|
||||
?assertEqual("ok\n", emqx_mgmt_cli:clients(["kick", "client12"])),
|
||||
timer:sleep(500),
|
||||
?assertEqual("ok~n", emqx_mgmt_cli:clients(["kick", "client12"])),
|
||||
?assertEqual("ok\n", emqx_mgmt_cli:clients(["kick", "client12"])),
|
||||
receive
|
||||
{'EXIT', T, _} ->
|
||||
ok
|
||||
|
@ -272,8 +272,8 @@ t_subscriptions_cmd(_) ->
|
|||
timer:sleep(300),
|
||||
[?assertMatch({match, _} , re:run(Result, "b/b/c"))
|
||||
|| Result <- emqx_mgmt_cli:subscriptions(["show", <<"client">>])],
|
||||
?assertEqual(emqx_mgmt_cli:subscriptions(["add", "client", "b/b/c", "0"]), "ok~n"),
|
||||
?assertEqual(emqx_mgmt_cli:subscriptions(["del", "client", "b/b/c"]), "ok~n"),
|
||||
?assertEqual(emqx_mgmt_cli:subscriptions(["add", "client", "b/b/c", "0"]), "ok\n"),
|
||||
?assertEqual(emqx_mgmt_cli:subscriptions(["del", "client", "b/b/c"]), "ok\n"),
|
||||
unmock_print().
|
||||
|
||||
t_listeners_cmd_old(_) ->
|
||||
|
@ -325,7 +325,7 @@ t_plugins_cmd(_) ->
|
|||
),
|
||||
?assertEqual(
|
||||
emqx_mgmt_cli:plugins(["unload", "emqx_management"]),
|
||||
"Plugin emqx_management can not be unloaded.~n"
|
||||
"Plugin emqx_management can not be unloaded.\n"
|
||||
),
|
||||
unmock_print().
|
||||
|
||||
|
@ -359,7 +359,7 @@ t_cli(_) ->
|
|||
mock_print() ->
|
||||
catch meck:unload(emqx_ctl),
|
||||
meck:new(emqx_ctl, [non_strict, passthrough]),
|
||||
meck:expect(emqx_ctl, print, fun(Arg) -> emqx_ctl:format(Arg) end),
|
||||
meck:expect(emqx_ctl, print, fun(Arg) -> emqx_ctl:format(Arg, []) end),
|
||||
meck:expect(emqx_ctl, print, fun(Msg, Arg) -> emqx_ctl:format(Msg, Arg) end),
|
||||
meck:expect(emqx_ctl, usage, fun(Usages) -> emqx_ctl:format_usage(Usages) end),
|
||||
meck:expect(emqx_ctl, usage, fun(Cmd, Descr) -> emqx_ctl:format_usage(Cmd, Descr) end).
|
||||
|
|
|
@ -105,10 +105,9 @@ cli_usage(_) ->
|
|||
mock_print() ->
|
||||
catch meck:unload(emqx_ctl),
|
||||
meck:new(emqx_ctl, [non_strict, passthrough]),
|
||||
meck:expect(emqx_ctl, print, fun(Arg) -> emqx_ctl:format(Arg) end),
|
||||
meck:expect(emqx_ctl, print, fun(Arg) -> emqx_ctl:format(Arg, []) end),
|
||||
meck:expect(emqx_ctl, print, fun(Msg, Arg) -> emqx_ctl:format(Msg, Arg) end),
|
||||
meck:expect(emqx_ctl, usage, fun(Usages) -> emqx_ctl:format_usage(Usages) end).
|
||||
|
||||
unmock_print() ->
|
||||
meck:unload().
|
||||
|
||||
|
|
|
@ -538,7 +538,7 @@ t_rules_cli(_Config) ->
|
|||
?assertMatch({match, _}, re:run(RUpdate, "updated")),
|
||||
|
||||
RDelete = emqx_rule_engine_cli:rules(["delete", RuleId]),
|
||||
?assertEqual("ok~n", RDelete),
|
||||
?assertEqual("ok\n", RDelete),
|
||||
%ct:pal("RDelete : ~p", [RDelete]),
|
||||
%ct:pal("table action params after deleted: ~p", [ets:tab2list(emqx_action_instance_params)]),
|
||||
|
||||
|
@ -578,7 +578,7 @@ t_resources_cli(_Config) ->
|
|||
%ct:pal("RShow : ~p", [RShow]),
|
||||
|
||||
RDelete = emqx_rule_engine_cli:resources(["delete", ResId]),
|
||||
?assertEqual("ok~n", RDelete),
|
||||
?assertEqual("ok\n", RDelete),
|
||||
|
||||
RShow2 = emqx_rule_engine_cli:resources(["show", ResId]),
|
||||
?assertMatch({match, _}, re:run(RShow2, "Cannot found")),
|
||||
|
@ -1387,7 +1387,7 @@ t_metrics1(_Config) ->
|
|||
?assertEqual(0, emqx_rule_metrics:get_rules_passed(RuleId)),
|
||||
?assertEqual(0, emqx_rule_metrics:get_rules_failed(RuleId)),
|
||||
?assertEqual(0, emqx_rule_metrics:get_rules_exception(RuleId)),
|
||||
?assertEqual(0, emqx_rule_metrics:get_rules_no_result(RuleId)),
|
||||
?assertEqual(0, emqx_rule_metrics:get_rules_no_result(RuleId)),
|
||||
{ok, Client} = emqtt:start_link([{username, <<"emqx">>}]),
|
||||
{ok, _} = emqtt:connect(Client),
|
||||
ct:sleep(200),
|
||||
|
@ -2711,7 +2711,7 @@ set_special_configs(_App) ->
|
|||
mock_print() ->
|
||||
catch meck:unload(emqx_ctl),
|
||||
meck:new(emqx_ctl, [non_strict, passthrough]),
|
||||
meck:expect(emqx_ctl, print, fun(Arg) -> emqx_ctl:format(Arg) end),
|
||||
meck:expect(emqx_ctl, print, fun(Arg) -> emqx_ctl:format(Arg, []) end),
|
||||
meck:expect(emqx_ctl, print, fun(Msg, Arg) -> emqx_ctl:format(Msg, Arg) end),
|
||||
meck:expect(emqx_ctl, usage, fun(Usages) -> emqx_ctl:format_usage(Usages) end),
|
||||
meck:expect(emqx_ctl, usage, fun(Cmd, Descr) -> emqx_ctl:format_usage(Cmd, Descr) end).
|
||||
|
@ -2763,4 +2763,3 @@ t_clear_resource(_) ->
|
|||
|
||||
t_clear_action(_) ->
|
||||
error('TODO').
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ t_join_cluster(_) ->
|
|||
mock_print() ->
|
||||
catch meck:unload(emqx_ctl),
|
||||
meck:new(emqx_ctl, [non_strict, passthrough]),
|
||||
meck:expect(emqx_ctl, print, fun(Arg) -> emqx_ctl:format(Arg) end),
|
||||
meck:expect(emqx_ctl, print, fun(Arg) -> emqx_ctl:format(Arg, []) end),
|
||||
meck:expect(emqx_ctl, print, fun(Msg, Arg) -> emqx_ctl:format(Msg, Arg) end),
|
||||
meck:expect(emqx_ctl, usage, fun(Usages) -> emqx_ctl:format_usage(Usages) end),
|
||||
meck:expect(emqx_ctl, usage, fun(Cmd, Descr) -> emqx_ctl:format_usage(Cmd, Descr) end).
|
||||
|
|
|
@ -43,8 +43,7 @@
|
|||
]).
|
||||
|
||||
%% Exports mainly for test cases
|
||||
-export([ format/1
|
||||
, format/2
|
||||
-export([ format/2
|
||||
, format_usage/1
|
||||
, format_usage/2
|
||||
]).
|
||||
|
@ -137,7 +136,7 @@ help() ->
|
|||
|
||||
-spec(print(io:format()) -> ok).
|
||||
print(Msg) ->
|
||||
io:format("~s", [format(Msg)]).
|
||||
io:format("~s", [format(Msg, [])]).
|
||||
|
||||
-spec(print(io:format(), [term()]) -> ok).
|
||||
print(Format, Args) ->
|
||||
|
@ -151,10 +150,6 @@ usage(UsageList) ->
|
|||
usage(CmdParams, Desc) ->
|
||||
io:format(format_usage(CmdParams, Desc)).
|
||||
|
||||
-spec(format(io:format()) -> string()).
|
||||
format(Msg) ->
|
||||
lists:flatten(io_lib:format("~s", [Msg])).
|
||||
|
||||
-spec(format(io:format(), [term()]) -> string()).
|
||||
format(Format, Args) ->
|
||||
lists:flatten(io_lib:format(Format, Args)).
|
||||
|
|
|
@ -70,7 +70,7 @@ t_print(_) ->
|
|||
ok = emqx_ctl:print("~s", [<<"~!@#$%^&*()">>]),
|
||||
% - check the output of the usage
|
||||
mock_print(),
|
||||
?assertEqual("help~n", emqx_ctl:print("help~n")),
|
||||
?assertEqual("help\n", emqx_ctl:print("help~n")),
|
||||
?assertEqual("help", emqx_ctl:print("~s", [help])),
|
||||
?assertEqual("~!@#$%^&*()", emqx_ctl:print("~s", [<<"~!@#$%^&*()">>])),
|
||||
unmock_print().
|
||||
|
@ -110,7 +110,7 @@ mock_print() ->
|
|||
%% proxy usage/1,2 and print/1,2 to format_xx/1,2 funcs
|
||||
catch meck:unload(emqx_ctl),
|
||||
meck:new(emqx_ctl, [non_strict, passthrough]),
|
||||
meck:expect(emqx_ctl, print, fun(Arg) -> emqx_ctl:format(Arg) end),
|
||||
meck:expect(emqx_ctl, print, fun(Arg) -> emqx_ctl:format(Arg, []) end),
|
||||
meck:expect(emqx_ctl, print, fun(Msg, Arg) -> emqx_ctl:format(Msg, Arg) end),
|
||||
meck:expect(emqx_ctl, usage, fun(Usages) -> emqx_ctl:format_usage(Usages) end),
|
||||
meck:expect(emqx_ctl, usage, fun(CmdParams, CmdDescr) ->
|
||||
|
|
Loading…
Reference in New Issue