From d0eaa5192854a91cb70f4e08837fc141919b7cc3 Mon Sep 17 00:00:00 2001 From: Gilbert Wong Date: Thu, 30 Aug 2018 22:16:31 +0800 Subject: [PATCH] add emqx listeners suite --- Makefile | 5 ++- test/emqx_listeners_SUITE.erl | 72 +++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 test/emqx_listeners_SUITE.erl diff --git a/Makefile b/Makefile index aba0d4ac4..6e888a53e 100644 --- a/Makefile +++ b/Makefile @@ -37,8 +37,9 @@ EUNIT_OPTS = verbose CT_SUITES = emqx emqx_connection emqx_session emqx_access emqx_base62 emqx_broker emqx_client emqx_cm emqx_frame emqx_guid emqx_inflight \ emqx_json emqx_keepalive emqx_lib emqx_metrics emqx_misc emqx_mod emqx_mqtt_caps \ - emqx_mqtt_compat emqx_mqtt_properties emqx_mqueue emqx_message emqx_net emqx_pqueue emqx_router emqx_sm \ - emqx_stats emqx_tables emqx_time emqx_topic emqx_trie emqx_vm emqx_zone emqx_mountpoint + emqx_mqtt_compat emqx_mqtt_properties emqx_mqueue emqx_net emqx_pqueue emqx_router emqx_sm \ + emqx_stats emqx_tables emqx_time emqx_topic emqx_trie emqx_vm emqx_zone \ + emqx_mountpoint emqx_listeners CT_OPTS = -cover test/ct.cover.spec -erl_args -name emqxct@127.0.0.1 diff --git a/test/emqx_listeners_SUITE.erl b/test/emqx_listeners_SUITE.erl new file mode 100644 index 000000000..f826e1798 --- /dev/null +++ b/test/emqx_listeners_SUITE.erl @@ -0,0 +1,72 @@ +%% Copyright (c) 2018 EMQ Technologies Co., Ltd. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. + +-module(emqx_listeners_SUITE). + +-compile(export_all). +-compile(nowarn_export_all). + +-include_lib("eunit/include/eunit.hrl"). + +-include_lib("common_test/include/ct.hrl"). + +-include("emqx.hrl"). +-include("emqx_mqtt.hrl"). + +all() -> + [start_stop_listeners, + restart_listeners]. + +init_per_suite(Config) -> + NewConfig = generate_config(), + lists:foreach(fun set_app_env/1, NewConfig), + Config. + +end_per_suite(_Config) -> + ok. + +start_stop_listeners() -> + emqx_listeners:start(), + emqx_listeners:stop(). + + +restart_listeners() -> + ok = emqx_listeners:restart(). + +generate_config() -> + Schema = cuttlefish_schema:files([local_path(["priv", "emqx.schema"])]), + Conf = conf_parse:file([local_path(["etc", "emqx.conf"])]), + cuttlefish_generator:map(Schema, Conf). + +set_app_env({App, Lists}) -> + lists:foreach(fun({acl_file, _Var}) -> + application:set_env(App, acl_file, local_path(["etc", "acl.conf"])); + ({plugins_loaded_file, _Var}) -> + application:set_env(App, plugins_loaded_file, local_path(["test", "emqx_SUITE_data","loaded_plugins"])); + ({Par, Var}) -> + application:set_env(App, Par, Var) + end, Lists). + +local_path(Components, Module) -> + filename:join([get_base_dir(Module) | Components]). + +local_path(Components) -> + local_path(Components, ?MODULE). + +get_base_dir(Module) -> + {file, Here} = code:is_loaded(Module), + filename:dirname(filename:dirname(Here)). + +get_base_dir() -> + get_base_dir(?MODULE).