test: fix config load for lib-ee tests

This commit is contained in:
Zaiming (Stone) Shi 2022-12-07 15:50:50 +01:00
parent 31098d6c67
commit f3b069a0d9
5 changed files with 41 additions and 32 deletions

View File

@ -3,6 +3,7 @@ REDIS_TAG=6
MONGO_TAG=5
PGSQL_TAG=13
LDAP_TAG=2.4.50
INFLUXDB_TAG=2.5.0
TARGET=emqx/emqx
EMQX_TAG=build-alpine-amd64

View File

@ -61,7 +61,7 @@ mix-deps-get: $(ELIXIR_COMMON_DEPS)
@mix deps.get
.PHONY: eunit
eunit: $(REBAR) conf-segs
eunit: $(REBAR) merge-config
@ENABLE_COVER_COMPILE=1 $(REBAR) eunit -v -c --cover_export_name $(PROFILE)-eunit
.PHONY: proper
@ -69,11 +69,11 @@ proper: $(REBAR)
@ENABLE_COVER_COMPILE=1 $(REBAR) proper -d test/props -c
.PHONY: test-compile
test-compile: $(REBAR) conf-segs
test-compile: $(REBAR) merge-config
$(REBAR) as test compile
.PHONY: ct
ct: $(REBAR) conf-segs
ct: $(REBAR) merge-config
@ENABLE_COVER_COMPILE=1 $(REBAR) ct --name $(CT_NODE_NAME) -c -v --cover_export_name $(PROFILE)-ct
.PHONY: static_checks
@ -224,7 +224,7 @@ ALL_DOCKERS = $(REL_PROFILES) $(REL_PROFILES:%=%-elixir)
$(foreach zt,$(ALL_DOCKERS),$(eval $(call gen-docker-target,$(zt))))
.PHONY:
conf-segs:
merge-config:
@$(SCRIPTS)/merge-config.escript
@$(SCRIPTS)/merge-i18n.escript

View File

@ -28,7 +28,6 @@
boot_modules/1,
start_apps/1,
start_apps/2,
start_app/4,
stop_apps/1,
reload/2,
app_path/2,
@ -165,13 +164,15 @@ start_apps(Apps) ->
start_apps(Apps, fun(_) -> ok end).
-spec start_apps(Apps :: apps(), Handler :: special_config_handler()) -> ok.
start_apps(Apps, Handler) when is_function(Handler) ->
start_apps(Apps, SpecAppConfig) when is_function(SpecAppConfig) ->
%% Load all application code to beam vm first
%% Because, minirest, ekka etc.. application will scan these modules
lists:foreach(fun load/1, [emqx | Apps]),
%% load emqx_conf config before starting ekka
render_and_load_app_config(emqx_conf),
ok = start_ekka(),
ok = emqx_ratelimiter_SUITE:load_conf(),
lists:foreach(fun(App) -> start_app(App, Handler) end, [emqx | Apps]).
lists:foreach(fun(App) -> start_app(App, SpecAppConfig) end, [emqx | Apps]).
load(App) ->
case application:load(App) of
@ -180,13 +181,35 @@ load(App) ->
{error, Reason} -> error({failed_to_load_app, App, Reason})
end.
start_app(App, Handler) ->
start_app(
App,
app_schema(App),
app_path(App, filename:join(["etc", app_conf_file(App)])),
Handler
).
render_and_load_app_config(App) ->
Schema = app_schema(App),
Conf = app_path(App, filename:join(["etc", app_conf_file(App)])),
try
do_render_app_config(App, Schema, Conf)
catch
throw:E:St ->
%% turn throw into error
error({Conf, E, St})
end.
do_render_app_config(App, Schema, ConfigFile) ->
Vars = mustache_vars(App),
RenderedConfigFile = render_config_file(ConfigFile, Vars),
read_schema_configs(Schema, RenderedConfigFile),
force_set_config_file_paths(App, [RenderedConfigFile]),
copy_certs(App, RenderedConfigFile),
ok.
start_app(App, SpecAppConfig) ->
render_and_load_app_config(App),
SpecAppConfig(App),
case application:ensure_all_started(App) of
{ok, _} ->
ok = ensure_dashboard_listeners_started(App),
ok;
{error, Reason} ->
error({failed_to_start_app, App, Reason})
end.
app_conf_file(emqx_conf) -> "emqx.conf.all";
app_conf_file(App) -> atom_to_list(App) ++ ".conf".
@ -208,21 +231,6 @@ mustache_vars(App) ->
{platform_log_dir, app_path(App, "log")}
].
start_app(App, Schema, ConfigFile, SpecAppConfig) ->
Vars = mustache_vars(App),
RenderedConfigFile = render_config_file(ConfigFile, Vars),
read_schema_configs(Schema, RenderedConfigFile),
force_set_config_file_paths(App, [RenderedConfigFile]),
copy_certs(App, RenderedConfigFile),
SpecAppConfig(App),
case application:ensure_all_started(App) of
{ok, _} ->
ok = ensure_dashboard_listeners_started(App),
ok;
{error, Reason} ->
error({failed_to_start_app, App, Reason})
end.
render_config_file(ConfigFile, Vars0) ->
Temp =
case file:read_file(ConfigFile) of

View File

@ -385,8 +385,8 @@ defmodule EMQXUmbrella.MixProject do
assigns = template_vars(release, release_type, package_type, edition_type)
# This is generated by `scripts/merge-config.escript` or `make
# conf-segs`. So, this should be run before the release.
# This is generated by `scripts/merge-config.escript` or `make merge-config`
# So, this should be run before the release.
# TODO: run as a "compiler" step???
render_template(
"apps/emqx_conf/etc/emqx.conf.all",

View File

@ -29,7 +29,7 @@ main(_) ->
case IsEnterprise of
true ->
EnterpriseCfgs = get_all_cfgs("lib-ee/"),
EnterpriseCfgs = get_all_cfgs("lib-ee"),
EnterpriseConf = merge("", EnterpriseCfgs),
ok = file:write_file("apps/emqx_conf/etc/emqx-enterprise.conf.all", EnterpriseConf);
false ->