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:
commit
2eb1bb2b13
|
@ -307,6 +307,13 @@ fields("ctx_delivery_dropped") ->
|
|||
{"from_clientid", sc(binary(), #{desc => ?DESC("event_from_clientid")})},
|
||||
{"from_username", sc(binary(), #{desc => ?DESC("event_from_username")})}
|
||||
| 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() ->
|
||||
|
@ -324,7 +331,8 @@ rule_input_message_context() ->
|
|||
ref("ctx_connack"),
|
||||
ref("ctx_check_authz_complete"),
|
||||
ref("ctx_bridge_mqtt"),
|
||||
ref("ctx_delivery_dropped")
|
||||
ref("ctx_delivery_dropped"),
|
||||
ref("ctx_schema_validation_failed")
|
||||
]),
|
||||
#{
|
||||
desc => ?DESC("test_context"),
|
||||
|
|
|
@ -197,6 +197,8 @@ is_test_runtime_env() ->
|
|||
|
||||
%% Most events have the original `topic' input, but their own topic (i.e.: `$events/...')
|
||||
%% is different from `topic'.
|
||||
get_in_topic(#{event_type := schema_validation_failed}) ->
|
||||
<<"$events/schema_validation_failed">>;
|
||||
get_in_topic(Context) ->
|
||||
case maps:find(event_topic, Context) of
|
||||
{ok, EventTopic} ->
|
||||
|
|
|
@ -214,6 +214,21 @@ t_ctx_delivery_dropped(_) ->
|
|||
Expected = check_result([from_clientid, from_username, reason, qos, topic], [], Context),
|
||||
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(_) ->
|
||||
SQL =
|
||||
<<"SELECT mongo_date() as mongo_date FROM \"$events/client_check_authz_complete\"">>,
|
||||
|
|
|
@ -360,6 +360,12 @@ event_username.desc:
|
|||
event_username.label:
|
||||
"""Username"""
|
||||
|
||||
event_validation.desc:
|
||||
"""Validation"""
|
||||
|
||||
event_validation.label:
|
||||
"""Validation"""
|
||||
|
||||
root_rule_info.desc:
|
||||
"""Schema for rule info"""
|
||||
|
||||
|
|
Loading…
Reference in New Issue