fix: avoid 'rule_test' api crash
This commit is contained in:
parent
28b7021322
commit
685b06eeed
|
@ -278,7 +278,9 @@ replace_sql_clrf(#{<<"sql">> := SQL} = Params) ->
|
|||
{error, {parse_error, Reason}} ->
|
||||
{400, #{code => 'BAD_REQUEST', message => err_msg(Reason)}};
|
||||
{error, nomatch} ->
|
||||
{412, #{code => 'NOT_MATCH', message => <<"SQL Not Match">>}}
|
||||
{412, #{code => 'NOT_MATCH', message => <<"SQL Not Match">>}};
|
||||
{error, Reason} ->
|
||||
{400, #{code => 'BAD_REQUEST', message => err_msg(Reason)}}
|
||||
end
|
||||
).
|
||||
|
||||
|
|
|
@ -80,4 +80,29 @@ t_crud_rule_api(_Config) ->
|
|||
{404, #{code := _, message := _Message}},
|
||||
emqx_rule_engine_api:'/rules/:id'(get, #{bindings => #{id => RuleID}})
|
||||
),
|
||||
|
||||
?assertMatch(
|
||||
{400, #{
|
||||
code := 'BAD_REQUEST',
|
||||
message := <<"{select_and_transform_error,{error,{decode_json_failed,", _/binary>>
|
||||
}},
|
||||
emqx_rule_engine_api:'/rule_test'(post, test_rule_params())
|
||||
),
|
||||
ok.
|
||||
|
||||
test_rule_params() ->
|
||||
#{
|
||||
body => #{
|
||||
<<"context">> =>
|
||||
#{
|
||||
<<"clientid">> => <<"c_emqx">>,
|
||||
<<"event_type">> => <<"message_publish">>,
|
||||
<<"payload">> => <<"{\"msg\": \"hel">>,
|
||||
<<"qos">> => 1,
|
||||
<<"topic">> => <<"t/a">>,
|
||||
<<"username">> => <<"u_emqx">>
|
||||
},
|
||||
<<"sql">> =>
|
||||
<<"SELECT\n payload.msg\nFROM\n \"t/#\"">>
|
||||
}
|
||||
}.
|
||||
|
|
Loading…
Reference in New Issue