Generate a config file for testing
Prior to this change, the template file etc/emqx.conf is used directly in testing, as a result, mustache style directories are created e.g. `{{ platform_log_dir }}` which should have been replaced with a config varialbe e.g. `log` In this change, Makefile targets are added as `ct` dependency to download bbmustach, load the template input, replace with variableds defined in 'vars' file, finally to etc/gen.emqx.conf. The direct usage of etc/emqx.conf in test code are replaced with gen.emqx.conf
This commit is contained in:
parent
60fb2a1007
commit
3a94d7ddae
|
@ -32,3 +32,5 @@ rebar3.crashdump
|
||||||
.DS_Store
|
.DS_Store
|
||||||
rebar.config
|
rebar.config
|
||||||
emqx.iml
|
emqx.iml
|
||||||
|
bbmustache/
|
||||||
|
etc/gen.emqx.conf
|
||||||
|
|
27
Makefile
27
Makefile
|
@ -51,6 +51,29 @@ DIALYZER_OPTS := --verbose --statistics -Werror_handling -Wrace_conditions #-Wun
|
||||||
|
|
||||||
include erlang.mk
|
include erlang.mk
|
||||||
|
|
||||||
app.config::
|
clean:: gen-clean
|
||||||
./deps/cuttlefish/cuttlefish -l info -e etc/ -c etc/emqx.conf -i priv/emqx.schema -d data/
|
|
||||||
|
.PHONY: gen-clean
|
||||||
|
gen-clean:
|
||||||
|
@rm -rf bbmustache
|
||||||
|
@rm -f etc/gen.emqx.conf
|
||||||
|
|
||||||
|
bbmustache:
|
||||||
|
$(verbose) git clone https://github.com/soranoba/bbmustache.git && pushd bbmustache && ./rebar3 compile && popd
|
||||||
|
|
||||||
|
# This hack is to generate a conf file for testing
|
||||||
|
# relx overlay is used for release
|
||||||
|
etc/gen.emqx.conf: bbmustache etc/emqx.conf
|
||||||
|
$(verbose) erl -noshell -pa bbmustache/_build/default/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)."
|
||||||
|
|
||||||
|
app.config: etc/gen.emqx.conf
|
||||||
|
$(verbose) ./deps/cuttlefish/cuttlefish -l info -e etc/ -c etc/gen.emqx.conf -i priv/emqx.schema -d data/
|
||||||
|
|
||||||
|
ct: app.config
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ run_teardown_steps() ->
|
||||||
|
|
||||||
generate_config() ->
|
generate_config() ->
|
||||||
Schema = cuttlefish_schema:files([local_path(["priv", "emqx.schema"])]),
|
Schema = cuttlefish_schema:files([local_path(["priv", "emqx.schema"])]),
|
||||||
Conf = conf_parse:file([local_path(["etc", "emqx.conf"])]),
|
Conf = conf_parse:file([local_path(["etc", "gen.emqx.conf"])]),
|
||||||
cuttlefish_generator:map(Schema, Conf).
|
cuttlefish_generator:map(Schema, Conf).
|
||||||
|
|
||||||
get_base_dir(Module) ->
|
get_base_dir(Module) ->
|
||||||
|
|
|
@ -49,7 +49,7 @@ restart_listeners(_) ->
|
||||||
|
|
||||||
generate_config() ->
|
generate_config() ->
|
||||||
Schema = cuttlefish_schema:files([local_path(["priv", "emqx.schema"])]),
|
Schema = cuttlefish_schema:files([local_path(["priv", "emqx.schema"])]),
|
||||||
Conf = conf_parse:file([local_path(["etc", "emqx.conf"])]),
|
Conf = conf_parse:file([local_path(["etc", "gen.emqx.conf"])]),
|
||||||
cuttlefish_generator:map(Schema, Conf).
|
cuttlefish_generator:map(Schema, Conf).
|
||||||
|
|
||||||
set_app_env({App, Lists}) ->
|
set_app_env({App, Lists}) ->
|
||||||
|
|
Loading…
Reference in New Issue