Add test cases for 'reason/1'
This commit is contained in:
parent
3705f4f929
commit
65cb9dbf38
|
@ -32,6 +32,10 @@
|
||||||
, on_client_disconnected/4
|
, on_client_disconnected/4
|
||||||
]).
|
]).
|
||||||
|
|
||||||
|
-ifdef(TEST).
|
||||||
|
-export([ reason/1 ]).
|
||||||
|
-endif.
|
||||||
|
|
||||||
load(Env) ->
|
load(Env) ->
|
||||||
emqx_hooks:add('client.connected', {?MODULE, on_client_connected, [Env]}),
|
emqx_hooks:add('client.connected', {?MODULE, on_client_connected, [Env]}),
|
||||||
emqx_hooks:add('client.disconnected', {?MODULE, on_client_disconnected, [Env]}).
|
emqx_hooks:add('client.disconnected', {?MODULE, on_client_disconnected, [Env]}).
|
||||||
|
|
|
@ -69,6 +69,12 @@ t_mod_presence(_) ->
|
||||||
ok = emqtt:disconnect(C1),
|
ok = emqtt:disconnect(C1),
|
||||||
ok = emqx_mod_presence:unload([{qos, ?QOS_1}]).
|
ok = emqx_mod_presence:unload([{qos, ?QOS_1}]).
|
||||||
|
|
||||||
|
t_mod_presence_reason(_) ->
|
||||||
|
?assertEqual(normal, emqx_mod_presence:reason(normal)),
|
||||||
|
?assertEqual(discarded, emqx_mod_presence:reason({shutdown, discarded})),
|
||||||
|
?assertEqual(tcp_error, emqx_mod_presence:reason({tcp_error, einval})),
|
||||||
|
?assertEqual(internal_error, emqx_mod_presence:reason(<<"unknown error">>)).
|
||||||
|
|
||||||
recv_and_check_presence(ClientId, Presence) ->
|
recv_and_check_presence(ClientId, Presence) ->
|
||||||
{ok, #{qos := ?QOS_1, topic := Topic, payload := Payload}} = receive_publish(100),
|
{ok, #{qos := ?QOS_1, topic := Topic, payload := Payload}} = receive_publish(100),
|
||||||
?assertMatch([<<"$SYS">>, <<"brokers">>, _Node, <<"clients">>, ClientId, Presence],
|
?assertMatch([<<"$SYS">>, <<"brokers">>, _Node, <<"clients">>, ClientId, Presence],
|
||||||
|
|
Loading…
Reference in New Issue