Merge pull request #13290 from kjellwinblad/kjell/format_rule_cli/EMQX-12548
fix: do not crash when showing rule unsing the cmd interface
This commit is contained in:
commit
ba4fb0d3f9
|
@ -164,7 +164,7 @@
|
|||
|
||||
-type root_cfg_key() :: ?ROOT_KEY_ACTIONS | ?ROOT_KEY_SOURCES.
|
||||
|
||||
-export_type([root_cfg_key/0]).
|
||||
-export_type([root_cfg_key/0, bridge_v2_type/0, bridge_v2_name/0]).
|
||||
|
||||
%%====================================================================
|
||||
|
||||
|
|
|
@ -42,7 +42,9 @@
|
|||
func := builtin_action_func() | atom(),
|
||||
args => action_fun_args()
|
||||
}
|
||||
| bridge_channel_id().
|
||||
| bridge_channel_id()
|
||||
| {bridge_v2, emqx_bridge_v2:bridge_v2_type(), emqx_bridge_v2:bridge_v2_name()}
|
||||
| {bridge, emqx_utils_maps:config_key(), emqx_utils_maps:config_key(), bridge_channel_id()}.
|
||||
|
||||
-type rule() ::
|
||||
#{
|
||||
|
|
|
@ -95,6 +95,18 @@ format_action(BridgeChannelId) when is_binary(BridgeChannelId) ->
|
|||
io_lib:format("- Name: ~s\n"
|
||||
" Type: data-bridge\n"
|
||||
,[BridgeChannelId]
|
||||
);
|
||||
format_action({bridge, ActionType, ActionName, _Id}) ->
|
||||
io_lib:format("- Name: ~p\n"
|
||||
" Action Type: ~p\n"
|
||||
" Type: data-bridge\n"
|
||||
,[ActionName, ActionType]
|
||||
);
|
||||
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) ->
|
||||
|
|
|
@ -44,7 +44,8 @@ all() ->
|
|||
{group, metrics_simple},
|
||||
{group, metrics_fail},
|
||||
{group, metrics_fail_simple},
|
||||
{group, tracing}
|
||||
{group, tracing},
|
||||
{group, command_line}
|
||||
].
|
||||
|
||||
suite() ->
|
||||
|
@ -147,6 +148,9 @@ groups() ->
|
|||
]},
|
||||
{tracing, [], [
|
||||
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">>)),
|
||||
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(_) ->
|
||||
Id = <<"t_ensure_action_removed">>,
|
||||
GetSelectedData = <<"emqx_rule_sqltester:get_selected_data">>,
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
The following command previously printed nothing if the rule had a data bridge action attached to it. This is now fixed.
|
||||
|
||||
$ bin/emqx ctl rules show rule_0hyd
|
Loading…
Reference in New Issue