From 287859fe363ec6104699d13a7a4ddf806f714cff Mon Sep 17 00:00:00 2001 From: JianBo He Date: Fri, 22 Oct 2021 17:54:22 +0800 Subject: [PATCH] chore(gw): integrate emqx-conf --- apps/emqx_gateway/src/emqx_gateway_conf.erl | 4 ++-- .../emqx_gateway/test/emqx_gateway_api_SUITE.erl | 16 +++++++--------- .../test/emqx_gateway_conf_SUITE.erl | 7 ++----- apps/emqx_gateway/test/emqx_lwm2m_SUITE.erl | 5 +++-- apps/emqx_gateway/test/emqx_lwm2m_api_SUITE.erl | 5 +++-- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/apps/emqx_gateway/src/emqx_gateway_conf.erl b/apps/emqx_gateway/src/emqx_gateway_conf.erl index 557e46693..71b517730 100644 --- a/apps/emqx_gateway/src/emqx_gateway_conf.erl +++ b/apps/emqx_gateway/src/emqx_gateway_conf.erl @@ -224,10 +224,10 @@ remove_authn(GwName, ListenerRef) -> %% @private update(Req) -> - res(emqx:update_config([gateway], Req)). + res(emqx_conf:update([gateway], Req, #{override_to => cluster})). res({ok, _Result}) -> ok; -res({error, {pre_config_update,emqx_gateway_conf,Reason}}) -> {error, Reason}; +res({error, {error, {pre_config_update,emqx_gateway_conf,Reason}}}) -> {error, Reason}; res({error, Reason}) -> {error, Reason}. bin({LType, LName}) -> diff --git a/apps/emqx_gateway/test/emqx_gateway_api_SUITE.erl b/apps/emqx_gateway/test/emqx_gateway_api_SUITE.erl index 3f709fa5a..0998cab31 100644 --- a/apps/emqx_gateway/test/emqx_gateway_api_SUITE.erl +++ b/apps/emqx_gateway/test/emqx_gateway_api_SUITE.erl @@ -28,6 +28,10 @@ -include_lib("eunit/include/eunit.hrl"). +-define(CONF_DEFAULT, <<" +gateway {} +">>). + %%-------------------------------------------------------------------- %% Setup %%-------------------------------------------------------------------- @@ -35,18 +39,12 @@ all() -> emqx_common_test_helpers:all(?MODULE). init_per_suite(Conf) -> - %% FIXME: Magic line. for saving gateway schema name for emqx_config - emqx_config:init_load(emqx_gateway_schema, <<"gateway {}">>), - emqx_mgmt_api_test_util:init_suite([emqx_gateway]), - %% Start emqx-authn separately, due to emqx_authn_schema - %% not implementing the roots/0 method, it cannot be started with - %% emqx-ct-helpers at the moment. - {ok, _} = application:ensure_all_started(emqx_authn), + emqx_config:init_load(emqx_gateway_schema, ?CONF_DEFAULT), + emqx_mgmt_api_test_util:init_suite([emqx_conf, emqx_authn, emqx_gateway]), Conf. end_per_suite(Conf) -> - application:stop(emqx_authn), - emqx_mgmt_api_test_util:end_suite([emqx_gateway]), + emqx_mgmt_api_test_util:end_suite([emqx_gateway, emqx_authn, emqx_conf]), Conf. %%-------------------------------------------------------------------- diff --git a/apps/emqx_gateway/test/emqx_gateway_conf_SUITE.erl b/apps/emqx_gateway/test/emqx_gateway_conf_SUITE.erl index 5f8eed20a..58af7c91e 100644 --- a/apps/emqx_gateway/test/emqx_gateway_conf_SUITE.erl +++ b/apps/emqx_gateway/test/emqx_gateway_conf_SUITE.erl @@ -34,15 +34,12 @@ all() -> emqx_common_test_helpers:all(?MODULE). init_per_suite(Conf) -> - %% FIXME: Magic line. for saving gateway schema name for emqx_config emqx_config:init_load(emqx_gateway_schema, <<"gateway {}">>), - emqx_common_test_helpers:start_apps([emqx_gateway]), - {ok, _} = application:ensure_all_started(emqx_authn), + emqx_common_test_helpers:start_apps([emqx_conf, emqx_authn, emqx_gateway]), Conf. end_per_suite(_Conf) -> - application:stop(emqx_authn), - emqx_common_test_helpers:stop_apps([emqx_gateway]). + emqx_common_test_helpers:stop_apps([emqx_gateway, emqx_authn, emqx_conf]). init_per_testcase(_CaseName, Conf) -> _ = emqx_gateway_conf:unload_gateway(stomp), diff --git a/apps/emqx_gateway/test/emqx_lwm2m_SUITE.erl b/apps/emqx_gateway/test/emqx_lwm2m_SUITE.erl index 8f9e6108f..49079d579 100644 --- a/apps/emqx_gateway/test/emqx_lwm2m_SUITE.erl +++ b/apps/emqx_gateway/test/emqx_lwm2m_SUITE.erl @@ -150,12 +150,13 @@ groups() -> ]. init_per_suite(Config) -> - emqx_common_test_helpers:start_apps([]), + emqx_common_test_helpers:start_apps([emqx_conf]), Config. end_per_suite(Config) -> timer:sleep(300), - emqx_common_test_helpers:stop_apps([]), + {ok, _} = emqx_conf:remove([<<"gateway">>,<<"lwm2m">>], #{}), + emqx_common_test_helpers:stop_apps([emqx_conf]), Config. init_per_testcase(_AllTestCase, Config) -> diff --git a/apps/emqx_gateway/test/emqx_lwm2m_api_SUITE.erl b/apps/emqx_gateway/test/emqx_lwm2m_api_SUITE.erl index da3a3ed1f..8f11bca78 100644 --- a/apps/emqx_gateway/test/emqx_lwm2m_api_SUITE.erl +++ b/apps/emqx_gateway/test/emqx_lwm2m_api_SUITE.erl @@ -70,12 +70,13 @@ all() -> init_per_suite(Config) -> ok = emqx_config:init_load(emqx_gateway_schema, ?CONF_DEFAULT), - emqx_mgmt_api_test_util:init_suite([emqx_gateway]), + emqx_mgmt_api_test_util:init_suite([emqx_conf, emqx_gateway]), Config. end_per_suite(Config) -> timer:sleep(300), - emqx_mgmt_api_test_util:end_suite([emqx_gateway]), + {ok, _} = emqx_conf:remove([<<"gateway">>,<<"lwm2m">>], #{}), + emqx_mgmt_api_test_util:end_suite([emqx_gateway, emqx_conf]), Config. init_per_testcase(_AllTestCase, Config) ->