fix(rule apply test): add default values to context
Fixes: https://emqx.atlassian.net/browse/EMQX-12378
This commit is contained in:
parent
520e91c8fd
commit
ed16e678be
|
@ -52,7 +52,8 @@ do_apply_rule(
|
||||||
do_apply_matched_rule(
|
do_apply_matched_rule(
|
||||||
Rule,
|
Rule,
|
||||||
Context,
|
Context,
|
||||||
StopAfterRender
|
StopAfterRender,
|
||||||
|
EventTopics
|
||||||
);
|
);
|
||||||
false ->
|
false ->
|
||||||
{error, nomatch}
|
{error, nomatch}
|
||||||
|
@ -61,17 +62,21 @@ do_apply_rule(
|
||||||
case lists:member(InTopic, EventTopics) of
|
case lists:member(InTopic, EventTopics) of
|
||||||
true ->
|
true ->
|
||||||
%% the rule is for both publish and events, test it directly
|
%% the rule is for both publish and events, test it directly
|
||||||
do_apply_matched_rule(Rule, Context, StopAfterRender);
|
do_apply_matched_rule(Rule, Context, StopAfterRender, EventTopics);
|
||||||
false ->
|
false ->
|
||||||
{error, nomatch}
|
{error, nomatch}
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
do_apply_matched_rule(Rule, Context, StopAfterRender) ->
|
do_apply_matched_rule(Rule, Context, StopAfterRender, EventTopics) ->
|
||||||
update_process_trace_metadata(StopAfterRender),
|
update_process_trace_metadata(StopAfterRender),
|
||||||
|
FullContext = fill_default_values(
|
||||||
|
hd(EventTopics),
|
||||||
|
emqx_rule_maps:atom_key_map(Context)
|
||||||
|
),
|
||||||
ApplyRuleRes = emqx_rule_runtime:apply_rule(
|
ApplyRuleRes = emqx_rule_runtime:apply_rule(
|
||||||
Rule,
|
Rule,
|
||||||
Context,
|
FullContext,
|
||||||
apply_rule_environment()
|
apply_rule_environment()
|
||||||
),
|
),
|
||||||
reset_trace_process_metadata(StopAfterRender),
|
reset_trace_process_metadata(StopAfterRender),
|
||||||
|
@ -99,6 +104,7 @@ apply_rule_environment() -> #{}.
|
||||||
|
|
||||||
-spec test(#{sql := binary(), context := map()}) -> {ok, map() | list()} | {error, term()}.
|
-spec test(#{sql := binary(), context := map()}) -> {ok, map() | list()} | {error, term()}.
|
||||||
test(#{sql := Sql, context := Context}) ->
|
test(#{sql := Sql, context := Context}) ->
|
||||||
|
x:show(context, Context),
|
||||||
case emqx_rule_sqlparser:parse(Sql) of
|
case emqx_rule_sqlparser:parse(Sql) of
|
||||||
{ok, Select} ->
|
{ok, Select} ->
|
||||||
InTopic = get_in_topic(Context),
|
InTopic = get_in_topic(Context),
|
||||||
|
|
Loading…
Reference in New Issue