fix: do not crash when showing rule unsing the cmd interface
Before the change the command line command $ bin/emqx ctl rules show rule_0hyd would crash if the rule had bridge actions. This has now been fixed by adding a handler for printing bridge actions. Fixes: https://emqx.atlassian.net/browse/EMQX-12548
This commit is contained in:
parent
3f7723b2dc
commit
a4f855108c
|
@ -95,6 +95,12 @@ format_action(BridgeChannelId) when is_binary(BridgeChannelId) ->
|
||||||
io_lib:format("- Name: ~s\n"
|
io_lib:format("- Name: ~s\n"
|
||||||
" Type: data-bridge\n"
|
" Type: data-bridge\n"
|
||||||
,[BridgeChannelId]
|
,[BridgeChannelId]
|
||||||
|
);
|
||||||
|
format_action({bridge_v2, ActionType, ActionName}) ->
|
||||||
|
io_lib:format("- Name: ~p\n"
|
||||||
|
" Action Type: ~p\n"
|
||||||
|
" Type: data-bridge\n"
|
||||||
|
,[ActionName, ActionType]
|
||||||
).
|
).
|
||||||
|
|
||||||
left_pad(Str) ->
|
left_pad(Str) ->
|
||||||
|
|
|
@ -44,7 +44,8 @@ all() ->
|
||||||
{group, metrics_simple},
|
{group, metrics_simple},
|
||||||
{group, metrics_fail},
|
{group, metrics_fail},
|
||||||
{group, metrics_fail_simple},
|
{group, metrics_fail_simple},
|
||||||
{group, tracing}
|
{group, tracing},
|
||||||
|
{group, command_line}
|
||||||
].
|
].
|
||||||
|
|
||||||
suite() ->
|
suite() ->
|
||||||
|
@ -147,6 +148,9 @@ groups() ->
|
||||||
]},
|
]},
|
||||||
{tracing, [], [
|
{tracing, [], [
|
||||||
t_trace_rule_id
|
t_trace_rule_id
|
||||||
|
]},
|
||||||
|
{command_line, [], [
|
||||||
|
t_command_line_list_print_rule
|
||||||
]}
|
]}
|
||||||
].
|
].
|
||||||
|
|
||||||
|
@ -596,6 +600,26 @@ t_get_rule_ids_by_action(_) ->
|
||||||
?assertEqual([], emqx_rule_engine:get_rule_ids_by_action(<<"mysql:not_exists">>)),
|
?assertEqual([], emqx_rule_engine:get_rule_ids_by_action(<<"mysql:not_exists">>)),
|
||||||
ok = delete_rules_by_ids([<<"t_get_rule_ids_by_action">>]).
|
ok = delete_rules_by_ids([<<"t_get_rule_ids_by_action">>]).
|
||||||
|
|
||||||
|
%% Check that command line interface don't crash when listing and showing rules
|
||||||
|
t_command_line_list_print_rule(_) ->
|
||||||
|
ID = <<"t_command_line">>,
|
||||||
|
Rule1 = #{
|
||||||
|
id => ID,
|
||||||
|
sql => <<"SELECT * FROM \"t\"">>,
|
||||||
|
actions => [
|
||||||
|
#{function => console, args => #{}},
|
||||||
|
#{function => republish, args => #{}},
|
||||||
|
<<"mqtt:my_mqtt_bridge">>,
|
||||||
|
<<"mysql:foo">>
|
||||||
|
],
|
||||||
|
description => ID,
|
||||||
|
created_at => erlang:system_time(millisecond)
|
||||||
|
},
|
||||||
|
ok = create_rules([Rule1]),
|
||||||
|
ok = emqx_rule_engine_cli:cmd(["list"]),
|
||||||
|
ok = emqx_rule_engine_cli:cmd(["show", binary_to_list(ID)]),
|
||||||
|
ok = delete_rules_by_ids([ID]).
|
||||||
|
|
||||||
t_ensure_action_removed(_) ->
|
t_ensure_action_removed(_) ->
|
||||||
Id = <<"t_ensure_action_removed">>,
|
Id = <<"t_ensure_action_removed">>,
|
||||||
GetSelectedData = <<"emqx_rule_sqltester:get_selected_data">>,
|
GetSelectedData = <<"emqx_rule_sqltester:get_selected_data">>,
|
||||||
|
|
Loading…
Reference in New Issue