From d0131ec663d66732586bdfe07fb4a5e895875d7b Mon Sep 17 00:00:00 2001 From: spring2maz <40776645+spring2maz@users.noreply.github.com> Date: Fri, 3 May 2019 22:41:08 +0200 Subject: [PATCH] Pin emqx-ct-helpers v1.1 (#2495) * Pin emqx-ct-helpers v1.1.1 * Fix loaded_plugins touch command --- .gitignore | 1 + Makefile | 30 ++++-------------------------- rebar.config | 2 +- test/emqx_listeners_SUITE.erl | 20 +++++++++++++++++++- vars | 9 --------- 5 files changed, 25 insertions(+), 37 deletions(-) delete mode 100644 vars diff --git a/.gitignore b/.gitignore index ab0cbe156..16369a576 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,4 @@ rebar.lock xrefr erlang.mk *.coverdata +etc/emqx.conf.rendered diff --git a/Makefile b/Makefile index b515e7618..c5619892c 100644 --- a/Makefile +++ b/Makefile @@ -24,31 +24,11 @@ clean: gen-clean .PHONY: gen-clean gen-clean: - @rm -f etc/gen.emqx.conf - -## bbmustache is a mustache template library used to render templated config files -## for common tests. -BBMUSTACHE := _build/test/lib/bbmustache -$(BBMUSTACHE): - @rebar3 as test compile + @rm -f etc/emqx.conf.rendered ## Cuttlefish escript is built by default when cuttlefish app (as dependency) was built CUTTLEFISH_SCRIPT := _build/default/lib/cuttlefish/cuttlefish -app.config: etc/gen.emqx.conf - $(verbose) $(CUTTLEFISH_SCRIPT) -l info -e etc/ -c etc/gen.emqx.conf -i priv/emqx.schema -d data/ - -## NOTE: Mustache templating was resolved by relx overlay when building a release. -## This is only to generate a conf file for testing, -etc/gen.emqx.conf: $(BBMUSTACHE) etc/emqx.conf - @$(verbose) erl -noshell -pa _build/test/lib/bbmustache/ebin -eval \ - "{ok, Temp} = file:read_file('etc/emqx.conf'), \ - {ok, Vars0} = file:consult('vars'), \ - Vars = [{atom_to_list(N), list_to_binary(V)} || {N, V} <- Vars0], \ - Targ = bbmustache:render(Temp, Vars), \ - ok = file:write_file('etc/gen.emqx.conf', Targ), \ - halt(0)." - .PHONY: cover cover: @rebar3 cover @@ -69,17 +49,15 @@ deps: eunit: @rebar3 eunit -v -## 'ct-setup' is a pre hook for 'rebar3 ct', -## but not the makefile target ct's dependency -## because 'ct-setup' requires test dependencies to be compiled first .PHONY: ct-setup ct-setup: - @rebar3 as test compile + @mkdir -p data + @if [ ! -f data/loaded_plugins ]; then touch data/loaded_plugins; fi @ln -s -f '../../../../etc' _build/test/lib/emqx/ @ln -s -f '../../../../data' _build/test/lib/emqx/ .PHONY: ct -ct: app.config ct-setup +ct: ct-setup @rebar3 ct -v --readable=false --name $(CT_NODE_NAME) --suite=$(shell echo $(foreach var,$(CT_SUITES),test/$(var)_SUITE) | tr ' ' ',') ## Run one single CT with rebar3 diff --git a/rebar.config b/rebar.config index b2dd5bcaa..3bbe75002 100644 --- a/rebar.config +++ b/rebar.config @@ -30,7 +30,7 @@ [{deps, [ {meck, "0.8.13"} % hex , {bbmustache, "1.7.0"} % hex - , {emqx_ct_helpers, {git, "https://github.com/emqx/emqx-ct-helpers", {tag, "v1.0"}}} + , {emqx_ct_helpers, {git, "https://github.com/emqx/emqx-ct-helpers", {tag, "v1.1.1"}}} ]} ]} ]}. diff --git a/test/emqx_listeners_SUITE.erl b/test/emqx_listeners_SUITE.erl index d969699bc..cab8707d5 100644 --- a/test/emqx_listeners_SUITE.erl +++ b/test/emqx_listeners_SUITE.erl @@ -49,9 +49,27 @@ restart_listeners(_) -> ok = emqx_listeners:restart(), ok = emqx_listeners:stop(). +render_config_file() -> + Path = local_path(["etc", "emqx.conf"]), + {ok, Temp} = file:read_file(Path), + Vars0 = mustache_vars(), + Vars = [{atom_to_list(N), iolist_to_binary(V)} || {N, V} <- Vars0], + Targ = bbmustache:render(Temp, Vars), + NewName = Path ++ ".rendered", + ok = file:write_file(NewName, Targ), + NewName. + +mustache_vars() -> + [{platform_data_dir, local_path(["data"])}, + {platform_etc_dir, local_path(["etc"])}, + {platform_log_dir, local_path(["log"])}, + {platform_plugins_dir, local_path(["plugins"])} + ]. + generate_config() -> Schema = cuttlefish_schema:files([local_path(["priv", "emqx.schema"])]), - Conf = conf_parse:file([local_path(["etc", "gen.emqx.conf"])]), + ConfFile = render_config_file(), + Conf = conf_parse:file(ConfFile), cuttlefish_generator:map(Schema, Conf). set_app_env({App, Lists}) -> diff --git a/vars b/vars deleted file mode 100644 index fedd69a45..000000000 --- a/vars +++ /dev/null @@ -1,9 +0,0 @@ -%% vars here are for test only, not intended for release - -{platform_bin_dir, "bin"}. -{platform_data_dir, "data"}. -{platform_etc_dir, "etc"}. -{platform_lib_dir, "lib"}. -{platform_log_dir, "log"}. -{platform_plugins_dir, "plugins"}. -