Просмотр исходного кода

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

Fixes https://emqx.atlassian.net/browse/EMQX-12679
Thales Macedo Garitezi 1 год назад
Родитель
Сommit
2816170e9d

+ 9 - 1
apps/emqx_rule_engine/src/emqx_rule_api_schema.erl

@@ -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"),

+ 2 - 0
apps/emqx_rule_engine/src/emqx_rule_sqltester.erl

@@ -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} ->

+ 15 - 0
apps/emqx_rule_engine/test/emqx_rule_engine_api_rule_test_SUITE.erl

@@ -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\"">>,

+ 6 - 0
rel/i18n/emqx_rule_api_schema.hocon

@@ -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"""