Fix testcases for emqx_ws_connection

This commit is contained in:
terry-xiaoyu 2019-11-01 20:25:29 +08:00
parent 1ca2dafd63
commit b17a54d392
1 changed files with 4 additions and 17 deletions

View File

@ -52,10 +52,6 @@ init_per_testcase(_TestCase, Config) ->
ok = meck:expect(cowboy_req, parse_cookies, fun(_) -> undefined end), ok = meck:expect(cowboy_req, parse_cookies, fun(_) -> undefined end),
%% Meck Channel %% Meck Channel
ok = meck:new(emqx_channel, [passthrough, no_history]), ok = meck:new(emqx_channel, [passthrough, no_history]),
ok = meck:expect(emqx_channel, recvd,
fun(_Oct, Channel) ->
{ok, Channel}
end),
%% Meck Metrics %% Meck Metrics
ok = meck:new(emqx_metrics, [passthrough, no_history]), ok = meck:new(emqx_metrics, [passthrough, no_history]),
ok = meck:expect(emqx_metrics, inc, fun(_, _) -> ok end), ok = meck:expect(emqx_metrics, inc, fun(_, _) -> ok end),
@ -83,15 +79,7 @@ t_ws_conn_info(_) ->
#{socktype := ws, #{socktype := ws,
peername := {{127,0,0,1}, 3456}, peername := {{127,0,0,1}, 3456},
sockname := {{127,0,0,1}, 8883}, sockname := {{127,0,0,1}, 8883},
sockstate := idle} = SockInfo sockstate := running} = SockInfo
end).
t_ws_conn_stats(_) ->
with_ws_conn(fun(WsConn) ->
Stats = emqx_ws_connection:stats(WsConn),
lists:foreach(fun(Key) ->
0 = proplists:get_value(Key, Stats)
end, ?STATS_KEYS)
end). end).
t_websocket_init(_) -> t_websocket_init(_) ->
@ -100,14 +88,13 @@ t_websocket_init(_) ->
#{socktype := ws, #{socktype := ws,
peername := {{127,0,0,1}, 3456}, peername := {{127,0,0,1}, 3456},
sockname := {{127,0,0,1}, 8883}, sockname := {{127,0,0,1}, 8883},
sockstate := idle sockstate := running
} = SockInfo } = SockInfo
end). end).
t_websocket_handle_binary(_) -> t_websocket_handle_binary(_) ->
with_ws_conn(fun(WsConn) -> with_ws_conn(fun(WsConn) ->
ok = meck:expect(emqx_channel, recvd, fun(_Oct, Channel) -> Channel end), {ok, _} = websocket_handle({binary, [<<>>]}, WsConn)
{ok, WsConn} = websocket_handle({binary, [<<>>]}, WsConn)
end). end).
t_websocket_handle_ping_pong(_) -> t_websocket_handle_ping_pong(_) ->
@ -225,7 +212,7 @@ with_ws_conn(TestFun) ->
with_ws_conn(TestFun, []). with_ws_conn(TestFun, []).
with_ws_conn(TestFun, Opts) -> with_ws_conn(TestFun, Opts) ->
{ok, WsConn} = emqx_ws_connection:websocket_init( {ok, WsConn, _} = emqx_ws_connection:websocket_init(
[req, emqx_misc:merge_opts([{zone, external}], Opts)]), [req, emqx_misc:merge_opts([{zone, external}], Opts)]),
TestFun(WsConn). TestFun(WsConn).