diff --git a/apps/emqx/test/emqx_cth_suite.erl b/apps/emqx/test/emqx_cth_suite.erl index 5e91b92c9..042ef91db 100644 --- a/apps/emqx/test/emqx_cth_suite.erl +++ b/apps/emqx/test/emqx_cth_suite.erl @@ -58,7 +58,6 @@ -module(emqx_cth_suite). -include_lib("common_test/include/ct.hrl"). --include_lib("emqx/include/emqx_access_control.hrl"). -export([start/2]). -export([stop/1]). diff --git a/apps/emqx_gateway/test/emqx_gateway_auth_ct.erl b/apps/emqx_gateway/test/emqx_gateway_auth_ct.erl index 215302105..81ab2f368 100644 --- a/apps/emqx_gateway/test/emqx_gateway_auth_ct.erl +++ b/apps/emqx_gateway/test/emqx_gateway_auth_ct.erl @@ -238,9 +238,12 @@ http_authz_config() -> init_gateway_conf() -> ok = emqx_common_test_helpers:load_config( emqx_gateway_schema, - merge_conf([X:default_config() || X <- ?CONFS], []) + merge_conf(list_gateway_conf(), []) ). +list_gateway_conf() -> + [X:default_config() || X <- ?CONFS]. + merge_conf([Conf | T], Acc) -> case re:run(Conf, "\s*gateway\\.(.*)", [global, {capture, all_but_first, list}, dotall]) of {match, [[Content]]} -> diff --git a/apps/emqx_gateway/test/emqx_gateway_authz_SUITE.erl b/apps/emqx_gateway/test/emqx_gateway_authz_SUITE.erl index dd149133b..9ae464ebb 100644 --- a/apps/emqx_gateway/test/emqx_gateway_authz_SUITE.erl +++ b/apps/emqx_gateway/test/emqx_gateway_authz_SUITE.erl @@ -22,7 +22,7 @@ -include_lib("eunit/include/eunit.hrl"). -include_lib("common_test/include/ct.hrl"). --import(emqx_gateway_auth_ct, [init_gateway_conf/0, with_resource/3]). +-import(emqx_gateway_auth_ct, [with_resource/3]). -define(checkMatch(Guard), (fun(Expr) -> @@ -54,44 +54,33 @@ groups() -> emqx_gateway_auth_ct:init_groups(?MODULE, ?AUTHNS). init_per_group(AuthName, Conf) -> - {ok, _} = emqx_cluster_rpc:start_link(node(), emqx_cluster_rpc, 1000), - ok = emqx_authz_test_lib:reset_authorizers(), - emqx_gateway_auth_ct:start_auth(AuthName), - timer:sleep(500), - Conf. + Apps = emqx_cth_suite:start( + [ + {emqx_conf, "authorization { no_match = deny, cache { enable = false } }"}, + emqx_auth, + emqx_auth_http, + {emqx_gateway, emqx_gateway_auth_ct:list_gateway_conf()} + | emqx_gateway_test_utils:all_gateway_apps() + ], + #{work_dir => emqx_cth_suite:work_dir(Conf)} + ), + ok = emqx_gateway_auth_ct:start_auth(AuthName), + [{group_apps, Apps} | Conf]. end_per_group(AuthName, Conf) -> - emqx_gateway_auth_ct:stop_auth(AuthName), + ok = emqx_gateway_auth_ct:stop_auth(AuthName), + ok = emqx_cth_suite:stop(?config(group_apps, Conf)), Conf. init_per_suite(Config) -> - emqx_config:erase(gateway), - emqx_gateway_test_utils:load_all_gateway_apps(), - init_gateway_conf(), - emqx_mgmt_api_test_util:init_suite([ - grpc, emqx_conf, emqx_auth, emqx_auth_http, emqx_gateway - ]), - meck:new(emqx_authz_file, [non_strict, passthrough, no_history, no_link]), - meck:expect(emqx_authz_file, create, fun(S) -> S end), - application:ensure_all_started(cowboy), - emqx_gateway_auth_ct:start(), - Config. + {ok, Apps1} = application:ensure_all_started(grpc), + {ok, Apps2} = application:ensure_all_started(cowboy), + {ok, _} = emqx_gateway_auth_ct:start(), + [{suite_apps, Apps1 ++ Apps2} | Config]. end_per_suite(Config) -> - meck:unload(emqx_authz_file), - emqx_gateway_auth_ct:stop(), - ok = emqx_authz_test_lib:restore_authorizers(), - emqx_config:erase(gateway), - emqx_mgmt_api_test_util:end_suite([ - emqx_gateway, emqx_auth_http, emqx_auth, emqx_conf, grpc - ]), - Config. - -init_per_testcase(_Case, Config) -> - {ok, _} = emqx_cluster_rpc:start_link(node(), emqx_cluster_rpc, 1000), - Config. - -end_per_testcase(_Case, Config) -> + ok = emqx_gateway_auth_ct:stop(), + ok = emqx_cth_suite:stop_apps(?config(suite_apps, Config)), Config. %%------------------------------------------------------------------------------ diff --git a/apps/emqx_gateway/test/emqx_gateway_test_utils.erl b/apps/emqx_gateway/test/emqx_gateway_test_utils.erl index 950ae1bcf..2e8be5119 100644 --- a/apps/emqx_gateway/test/emqx_gateway_test_utils.erl +++ b/apps/emqx_gateway/test/emqx_gateway_test_utils.erl @@ -103,12 +103,18 @@ assert_fields_exist(Ks, Map) -> end, Ks ). + load_all_gateway_apps() -> - application:load(emqx_gateway_stomp), - application:load(emqx_gateway_mqttsn), - application:load(emqx_gateway_coap), - application:load(emqx_gateway_lwm2m), - application:load(emqx_gateway_exproto). + emqx_cth_suite:load_apps(all_gateway_apps()). + +all_gateway_apps() -> + [ + emqx_gateway_stomp, + emqx_gateway_mqttsn, + emqx_gateway_coap, + emqx_gateway_lwm2m, + emqx_gateway_exproto + ]. %%-------------------------------------------------------------------- %% http diff --git a/apps/emqx_gateway_mqttsn/test/emqx_sn_protocol_SUITE.erl b/apps/emqx_gateway_mqttsn/test/emqx_sn_protocol_SUITE.erl index 6d0d7128a..25d8bcc51 100644 --- a/apps/emqx_gateway_mqttsn/test/emqx_sn_protocol_SUITE.erl +++ b/apps/emqx_gateway_mqttsn/test/emqx_sn_protocol_SUITE.erl @@ -85,6 +85,12 @@ " listeners.udp.default {\n" " bind = 1884\n" " }\n" + "}\n" +>>). + +-define(CONF_DTLS, << + "\n" + "gateway.mqttsn {" " listeners.dtls.default {\n" " bind = 1885\n" " dtls_options {\n" @@ -110,7 +116,7 @@ init_per_suite(Config) -> {CACertfile, _} = emqx_cth_tls:write_cert(PrivDir, Root), {Certfile, Keyfile} = emqx_cth_tls:write_cert(PrivDir, Server), Conf = emqx_template:render_strict( - emqx_template:parse(?CONF_DEFAULT), + emqx_template:parse([?CONF_DEFAULT, ?CONF_DTLS]), #{ cacertfile => CACertfile, certfile => Certfile,