From a03f2dd64bd2f9115d3ef0e59d35e120d7d8bae6 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Mon, 1 May 2023 15:35:33 +0200 Subject: [PATCH] test: allow pre-load configs before emqx_conf app --- apps/emqx/src/emqx_config.erl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/emqx/src/emqx_config.erl b/apps/emqx/src/emqx_config.erl index c117bffba..3d5a9d2a4 100644 --- a/apps/emqx/src/emqx_config.erl +++ b/apps/emqx/src/emqx_config.erl @@ -360,12 +360,13 @@ read_override_confs() -> hocon:deep_merge(ClusterOverrides, LocalOverrides). %% keep the raw and non-raw conf has the same keys to make update raw conf easier. +%% TODO: remove raw_with_default as it's now always true. maybe_fill_defaults(SchemaMod, RawConf0, #{raw_with_default := true}) -> RootSchemas = hocon_schema:roots(SchemaMod), %% the roots which are missing from the loaded configs MissingRoots = lists:filtermap( fun({BinName, Sc}) -> - case maps:is_key(BinName, RawConf0) of + case maps:is_key(BinName, RawConf0) orelse is_already_loaded(BinName) of true -> false; false -> {true, Sc} end @@ -383,6 +384,13 @@ maybe_fill_defaults(SchemaMod, RawConf0, #{raw_with_default := true}) -> maybe_fill_defaults(_SchemaMod, RawConf, _Opts) -> RawConf. +%% So far, this can only return true when testing. +%% e.g. when testing an app, we need to load its config first +%% then start emqx_conf application which will load the +%% possibly empty config again (then filled with defaults). +is_already_loaded(Name) -> + ?MODULE:get_raw([Name], #{}) =/= #{}. + %% if a root is not found in the raw conf, fill it with default values. seed_default(Schema) -> case hocon_schema:field_schema(Schema, default) of