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) ->
|
t_acl_cli(_Config) ->
|
||||||
meck:new(emqx_ctl, [non_strict, passthrough]),
|
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, 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(Usages) -> emqx_ctl:format_usage(Usages) end),
|
||||||
meck:expect(emqx_ctl, usage, fun(Cmd, Descr) -> emqx_ctl:format_usage(Cmd, Descr) 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),
|
timer:sleep(300),
|
||||||
emqx_mgmt_cli:clients(["list"]),
|
emqx_mgmt_cli:clients(["list"]),
|
||||||
?assertMatch({match, _}, re:run(emqx_mgmt_cli:clients(["show", "client12"]), "client12")),
|
?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),
|
timer:sleep(500),
|
||||||
?assertEqual("ok~n", emqx_mgmt_cli:clients(["kick", "client12"])),
|
?assertEqual("ok\n", emqx_mgmt_cli:clients(["kick", "client12"])),
|
||||||
receive
|
receive
|
||||||
{'EXIT', T, _} ->
|
{'EXIT', T, _} ->
|
||||||
ok
|
ok
|
||||||
|
@ -272,8 +272,8 @@ t_subscriptions_cmd(_) ->
|
||||||
timer:sleep(300),
|
timer:sleep(300),
|
||||||
[?assertMatch({match, _} , re:run(Result, "b/b/c"))
|
[?assertMatch({match, _} , re:run(Result, "b/b/c"))
|
||||||
|| Result <- emqx_mgmt_cli:subscriptions(["show", <<"client">>])],
|
|| 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(["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(["del", "client", "b/b/c"]), "ok\n"),
|
||||||
unmock_print().
|
unmock_print().
|
||||||
|
|
||||||
t_listeners_cmd_old(_) ->
|
t_listeners_cmd_old(_) ->
|
||||||
|
@ -325,7 +325,7 @@ t_plugins_cmd(_) ->
|
||||||
),
|
),
|
||||||
?assertEqual(
|
?assertEqual(
|
||||||
emqx_mgmt_cli:plugins(["unload", "emqx_management"]),
|
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().
|
unmock_print().
|
||||||
|
|
||||||
|
@ -359,7 +359,7 @@ t_cli(_) ->
|
||||||
mock_print() ->
|
mock_print() ->
|
||||||
catch meck:unload(emqx_ctl),
|
catch meck:unload(emqx_ctl),
|
||||||
meck:new(emqx_ctl, [non_strict, passthrough]),
|
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, 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(Usages) -> emqx_ctl:format_usage(Usages) end),
|
||||||
meck:expect(emqx_ctl, usage, fun(Cmd, Descr) -> emqx_ctl:format_usage(Cmd, Descr) end).
|
meck:expect(emqx_ctl, usage, fun(Cmd, Descr) -> emqx_ctl:format_usage(Cmd, Descr) end).
|
||||||
|
|
|
@ -105,10 +105,9 @@ cli_usage(_) ->
|
||||||
mock_print() ->
|
mock_print() ->
|
||||||
catch meck:unload(emqx_ctl),
|
catch meck:unload(emqx_ctl),
|
||||||
meck:new(emqx_ctl, [non_strict, passthrough]),
|
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, 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(Usages) -> emqx_ctl:format_usage(Usages) end).
|
||||||
|
|
||||||
unmock_print() ->
|
unmock_print() ->
|
||||||
meck:unload().
|
meck:unload().
|
||||||
|
|
||||||
|
|
|
@ -538,7 +538,7 @@ t_rules_cli(_Config) ->
|
||||||
?assertMatch({match, _}, re:run(RUpdate, "updated")),
|
?assertMatch({match, _}, re:run(RUpdate, "updated")),
|
||||||
|
|
||||||
RDelete = emqx_rule_engine_cli:rules(["delete", RuleId]),
|
RDelete = emqx_rule_engine_cli:rules(["delete", RuleId]),
|
||||||
?assertEqual("ok~n", RDelete),
|
?assertEqual("ok\n", RDelete),
|
||||||
%ct:pal("RDelete : ~p", [RDelete]),
|
%ct:pal("RDelete : ~p", [RDelete]),
|
||||||
%ct:pal("table action params after deleted: ~p", [ets:tab2list(emqx_action_instance_params)]),
|
%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]),
|
%ct:pal("RShow : ~p", [RShow]),
|
||||||
|
|
||||||
RDelete = emqx_rule_engine_cli:resources(["delete", ResId]),
|
RDelete = emqx_rule_engine_cli:resources(["delete", ResId]),
|
||||||
?assertEqual("ok~n", RDelete),
|
?assertEqual("ok\n", RDelete),
|
||||||
|
|
||||||
RShow2 = emqx_rule_engine_cli:resources(["show", ResId]),
|
RShow2 = emqx_rule_engine_cli:resources(["show", ResId]),
|
||||||
?assertMatch({match, _}, re:run(RShow2, "Cannot found")),
|
?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_passed(RuleId)),
|
||||||
?assertEqual(0, emqx_rule_metrics:get_rules_failed(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_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, Client} = emqtt:start_link([{username, <<"emqx">>}]),
|
||||||
{ok, _} = emqtt:connect(Client),
|
{ok, _} = emqtt:connect(Client),
|
||||||
ct:sleep(200),
|
ct:sleep(200),
|
||||||
|
@ -2711,7 +2711,7 @@ set_special_configs(_App) ->
|
||||||
mock_print() ->
|
mock_print() ->
|
||||||
catch meck:unload(emqx_ctl),
|
catch meck:unload(emqx_ctl),
|
||||||
meck:new(emqx_ctl, [non_strict, passthrough]),
|
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, 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(Usages) -> emqx_ctl:format_usage(Usages) end),
|
||||||
meck:expect(emqx_ctl, usage, fun(Cmd, Descr) -> emqx_ctl:format_usage(Cmd, Descr) 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(_) ->
|
t_clear_action(_) ->
|
||||||
error('TODO').
|
error('TODO').
|
||||||
|
|
||||||
|
|
|
@ -143,7 +143,7 @@ t_join_cluster(_) ->
|
||||||
mock_print() ->
|
mock_print() ->
|
||||||
catch meck:unload(emqx_ctl),
|
catch meck:unload(emqx_ctl),
|
||||||
meck:new(emqx_ctl, [non_strict, passthrough]),
|
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, 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(Usages) -> emqx_ctl:format_usage(Usages) end),
|
||||||
meck:expect(emqx_ctl, usage, fun(Cmd, Descr) -> emqx_ctl:format_usage(Cmd, Descr) 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
|
%% Exports mainly for test cases
|
||||||
-export([ format/1
|
-export([ format/2
|
||||||
, format/2
|
|
||||||
, format_usage/1
|
, format_usage/1
|
||||||
, format_usage/2
|
, format_usage/2
|
||||||
]).
|
]).
|
||||||
|
@ -137,7 +136,7 @@ help() ->
|
||||||
|
|
||||||
-spec(print(io:format()) -> ok).
|
-spec(print(io:format()) -> ok).
|
||||||
print(Msg) ->
|
print(Msg) ->
|
||||||
io:format("~s", [format(Msg)]).
|
io:format("~s", [format(Msg, [])]).
|
||||||
|
|
||||||
-spec(print(io:format(), [term()]) -> ok).
|
-spec(print(io:format(), [term()]) -> ok).
|
||||||
print(Format, Args) ->
|
print(Format, Args) ->
|
||||||
|
@ -151,10 +150,6 @@ usage(UsageList) ->
|
||||||
usage(CmdParams, Desc) ->
|
usage(CmdParams, Desc) ->
|
||||||
io:format(format_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()).
|
-spec(format(io:format(), [term()]) -> string()).
|
||||||
format(Format, Args) ->
|
format(Format, Args) ->
|
||||||
lists:flatten(io_lib:format(Format, Args)).
|
lists:flatten(io_lib:format(Format, Args)).
|
||||||
|
|
|
@ -70,7 +70,7 @@ t_print(_) ->
|
||||||
ok = emqx_ctl:print("~s", [<<"~!@#$%^&*()">>]),
|
ok = emqx_ctl:print("~s", [<<"~!@#$%^&*()">>]),
|
||||||
% - check the output of the usage
|
% - check the output of the usage
|
||||||
mock_print(),
|
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("help", emqx_ctl:print("~s", [help])),
|
||||||
?assertEqual("~!@#$%^&*()", emqx_ctl:print("~s", [<<"~!@#$%^&*()">>])),
|
?assertEqual("~!@#$%^&*()", emqx_ctl:print("~s", [<<"~!@#$%^&*()">>])),
|
||||||
unmock_print().
|
unmock_print().
|
||||||
|
@ -110,7 +110,7 @@ mock_print() ->
|
||||||
%% proxy usage/1,2 and print/1,2 to format_xx/1,2 funcs
|
%% proxy usage/1,2 and print/1,2 to format_xx/1,2 funcs
|
||||||
catch meck:unload(emqx_ctl),
|
catch meck:unload(emqx_ctl),
|
||||||
meck:new(emqx_ctl, [non_strict, passthrough]),
|
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, 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(Usages) -> emqx_ctl:format_usage(Usages) end),
|
||||||
meck:expect(emqx_ctl, usage, fun(CmdParams, CmdDescr) ->
|
meck:expect(emqx_ctl, usage, fun(CmdParams, CmdDescr) ->
|
||||||
|
|
Loading…
Reference in New Issue