Merge pull request #13032 from kjellwinblad/kjell/no_ctx_message_validation_failed/EMQX-12354

fix: add handling of message_validation_failed ctx for rule testing
This commit is contained in:
Thales Macedo Garitezi 2024-05-15 11:20:18 -03:00 committed by GitHub
commit 2eb1bb2b13
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 32 additions and 1 deletions

View File

@ -307,6 +307,13 @@ fields("ctx_delivery_dropped") ->
{"from_clientid", sc(binary(), #{desc => ?DESC("event_from_clientid")})}, {"from_clientid", sc(binary(), #{desc => ?DESC("event_from_clientid")})},
{"from_username", sc(binary(), #{desc => ?DESC("event_from_username")})} {"from_username", sc(binary(), #{desc => ?DESC("event_from_username")})}
| msg_event_common_fields() | msg_event_common_fields()
];
fields("ctx_schema_validation_failed") ->
Event = 'schema.validation_failed',
[
{"event_type", event_type_sc(Event)},
{"validation", sc(binary(), #{desc => ?DESC("event_validation")})}
| msg_event_common_fields()
]. ].
rule_input_message_context() -> rule_input_message_context() ->
@ -324,7 +331,8 @@ rule_input_message_context() ->
ref("ctx_connack"), ref("ctx_connack"),
ref("ctx_check_authz_complete"), ref("ctx_check_authz_complete"),
ref("ctx_bridge_mqtt"), ref("ctx_bridge_mqtt"),
ref("ctx_delivery_dropped") ref("ctx_delivery_dropped"),
ref("ctx_schema_validation_failed")
]), ]),
#{ #{
desc => ?DESC("test_context"), desc => ?DESC("test_context"),

View File

@ -197,6 +197,8 @@ is_test_runtime_env() ->
%% Most events have the original `topic' input, but their own topic (i.e.: `$events/...') %% Most events have the original `topic' input, but their own topic (i.e.: `$events/...')
%% is different from `topic'. %% is different from `topic'.
get_in_topic(#{event_type := schema_validation_failed}) ->
<<"$events/schema_validation_failed">>;
get_in_topic(Context) -> get_in_topic(Context) ->
case maps:find(event_topic, Context) of case maps:find(event_topic, Context) of
{ok, EventTopic} -> {ok, EventTopic} ->

View File

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

View File

@ -360,6 +360,12 @@ event_username.desc:
event_username.label: event_username.label:
"""Username""" """Username"""
event_validation.desc:
"""Validation"""
event_validation.label:
"""Validation"""
root_rule_info.desc: root_rule_info.desc:
"""Schema for rule info""" """Schema for rule info"""