Skip to content
Permalink
Browse files

Compare atom to binary #121 (#122)

  • Loading branch information
terry-xiaoyu committed Nov 14, 2019
1 parent af89677 commit b240cc0434815bafb5cfcd366692257336d26e8c
Showing with 29 additions and 0 deletions.
  1. +4 −0 src/emqx_rule_runtime.erl
  2. +25 −0 test/emqx_rule_engine_SUITE.erl
@@ -284,6 +284,10 @@ compare(Op, L, R) when is_number(L), is_binary(R) ->
do_compare(Op, L, number(R));
compare(Op, L, R) when is_binary(L), is_number(R) ->
do_compare(Op, number(L), R);
compare(Op, L, R) when is_atom(L), is_binary(R) ->
do_compare(Op, atom_to_binary(L, utf8), R);
compare(Op, L, R) when is_binary(L), is_atom(R) ->
do_compare(Op, L, atom_to_binary(R, utf8));
compare(Op, L, R) ->
do_compare(Op, L, R).

@@ -83,6 +83,7 @@ groups() ->
]},
{runtime, [],
[t_events,
t_match_atom_and_binary,
t_sqlselect_0,
t_sqlselect_01,
t_sqlselect_02,
@@ -648,6 +649,30 @@ client_disconnected(Client) ->
verify_events_counter('client.disconnected'),
ok.

t_match_atom_and_binary(_Config) ->
ok = emqx_rule_engine:load_providers(),
TopicRule = create_simple_repub_rule(
<<"t2">>,
"SELECT * "
"FROM \"client.connected\" "
"WHERE username = 'emqx2' and auth_result = 'success' ",
<<"user:${username}">>),
{ok, Client} = emqx_client:start_link([{username, <<"emqx1">>}]),
{ok, _} = emqx_client:connect(Client),
{ok, _, _} = emqx_client:subscribe(Client, <<"t2">>, 0),
ct:sleep(100),
{ok, Client2} = emqx_client:start_link([{username, <<"emqx2">>}]),
{ok, _} = emqx_client:connect(Client2),
receive {publish, #{topic := T, payload := Payload}} ->
?assertEqual(<<"t2">>, T),
?assertEqual(<<"user:emqx2">>, Payload)
after 1000 ->
ct:fail(wait_for_t2)
end,

emqx_client:stop(Client),
emqx_rule_registry:remove_rule(TopicRule).

t_sqlselect_0(_Config) ->
%% Verify SELECT with and without 'AS'
Sql = "select * "

0 comments on commit b240cc0

Please sign in to comment.
You can’t perform that action at this time.