Merge pull request #13527 from thalesmg/20240726-r57-multiple-froms-sql-test

fix(rule engine tester): fix message publish with bridge source in from clause
This commit is contained in:
Thales Macedo Garitezi 2024-07-29 09:37:17 -03:00 committed by GitHub
commit 8913de10c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 39 additions and 3 deletions

View File

@ -115,11 +115,13 @@ test(#{sql := Sql, context := Context}) ->
true ->
%% test if the topic matches the topic filters in the rule
case emqx_topic:match_any(InTopic, EventTopics) of
true -> test_rule(Sql, Select, Context, EventTopics);
false -> {error, nomatch}
true ->
test_rule(Sql, Select, Context, EventTopics);
false ->
{error, nomatch}
end;
false ->
case lists:member(InTopic, EventTopics) of
case emqx_topic:match_any(InTopic, EventTopics) of
true ->
%% the rule is for both publish and events, test it directly
test_rule(Sql, Select, Context, EventTopics);

View File

@ -332,6 +332,38 @@ t_rule_test_smoke(_Config) ->
}
],
MultipleFrom = [
#{
expected => #{code => 200},
input =>
#{
<<"context">> =>
#{
<<"clientid">> => <<"c_emqx">>,
<<"event_type">> => <<"message_publish">>,
<<"qos">> => 1,
<<"topic">> => <<"t/a">>,
<<"username">> => <<"u_emqx">>
},
<<"sql">> =>
<<"SELECT\n *\nFROM\n \"t/#\", \"$bridges/mqtt:source\" ">>
}
},
#{
expected => #{code => 200},
input =>
#{
<<"context">> =>
#{
<<"clientid">> => <<"c_emqx">>,
<<"event_type">> => <<"message_publish">>,
<<"qos">> => 1,
<<"topic">> => <<"t/a">>,
<<"username">> => <<"u_emqx">>
},
<<"sql">> =>
<<"SELECT\n *\nFROM\n \"t/#\", \"$sources/mqtt:source\" ">>
}
},
#{
expected => #{code => 200},
input =>
@ -395,6 +427,7 @@ do_t_rule_test_smoke(#{input := Input, expected := #{code := ExpectedCode}} = Ca
{true, #{
expected => ExpectedCode,
hint => maps:get(hint, Case, <<>>),
input => Input,
got => Code,
resp_body => Body
}}

View File

@ -0,0 +1 @@
Fixed an issue where running a SQL test in Rule Engine for the Message Publish event when a `$bridges/...` source was included in the `FROM` clause would always yield no results.