chore: add `$events.message_transformation_failed` to rule engine tester

Fixes https://emqx.atlassian.net/browse/EMQX-12679
This commit is contained in:
Thales Macedo Garitezi 2024-07-11 13:57:08 -03:00
parent 5f595966d8
commit 2816170e9d
4 changed files with 32 additions and 1 deletions

View File

@ -326,6 +326,13 @@ fields("ctx_schema_validation_failed") ->
{"event_type", event_type_sc(Event)},
{"validation", sc(binary(), #{desc => ?DESC("event_validation")})}
| msg_event_common_fields()
];
fields("ctx_message_transformation_failed") ->
Event = 'message.transformation_failed',
[
{"event_type", event_type_sc(Event)},
{"transformation", sc(binary(), #{desc => ?DESC("event_transformation")})}
| msg_event_common_fields()
].
rule_input_message_context() ->
@ -345,7 +352,8 @@ rule_input_message_context() ->
ref("ctx_check_authn_complete"),
ref("ctx_bridge_mqtt"),
ref("ctx_delivery_dropped"),
ref("ctx_schema_validation_failed")
ref("ctx_schema_validation_failed"),
ref("ctx_message_transformation_failed")
]),
#{
desc => ?DESC("test_context"),

View File

@ -206,6 +206,8 @@ is_test_runtime_env() ->
%% is different from `topic'.
get_in_topic(#{event_type := schema_validation_failed}) ->
<<"$events/schema_validation_failed">>;
get_in_topic(#{event_type := message_transformation_failed}) ->
<<"$events/message_transformation_failed">>;
get_in_topic(Context) ->
case maps:find(event_topic, Context) of
{ok, EventTopic} ->

View File

@ -257,6 +257,21 @@ t_ctx_schema_validation_failed(_) ->
Expected = check_result([validation], [], Context),
do_test(SQL, Context, Expected).
t_ctx_message_transformation_failed(_) ->
SQL =
<<"SELECT transformation FROM \"$events/message_transformation_failed\"">>,
Context = #{
<<"clientid">> => <<"c_emqx">>,
<<"event_type">> => <<"message_transformation_failed">>,
<<"payload">> => <<"{\"msg\": \"hello\"}">>,
<<"qos">> => 1,
<<"topic">> => <<"t/a">>,
<<"username">> => <<"u_emqx">>,
<<"transformation">> => <<"m">>
},
Expected = check_result([transformation], [], Context),
do_test(SQL, Context, Expected).
t_mongo_date_function_should_return_string_in_test_env(_) ->
SQL =
<<"SELECT mongo_date() as mongo_date FROM \"$events/client_check_authz_complete\"">>,

View File

@ -366,6 +366,12 @@ event_validation.desc:
event_validation.label:
"""Validation"""
event_transformation.desc:
"""Transformation"""
event_transformation.label:
"""Transformation"""
root_rule_info.desc:
"""Schema for rule info"""