Преглед изворни кода

Merge pull request #13719 from zmstone/release-58

test: fix schema test
zmstone пре 1 година
родитељ
комит
b7eeac6037

+ 5 - 3
apps/emqx_enterprise/src/emqx_enterprise_schema.erl

@@ -110,7 +110,7 @@ fields("log_audit_handler") ->
             )}
             )}
     ] ++ CommonConfs1;
     ] ++ CommonConfs1;
 fields(Name) ->
 fields(Name) ->
-    ee_delegate(fields, ?EXTRA_SCHEMA_MODULES ++ ?EE_SCHEMA_MODULES, Name).
+    ee_delegate(fields, ee_mods(), Name).
 
 
 translations() ->
 translations() ->
     emqx_conf_schema:translations().
     emqx_conf_schema:translations().
@@ -125,7 +125,7 @@ translation(Name) ->
 desc("log_audit_handler") ->
 desc("log_audit_handler") ->
     ?DESC(emqx_conf_schema, "desc_audit_log_handler");
     ?DESC(emqx_conf_schema, "desc_audit_log_handler");
 desc(Name) ->
 desc(Name) ->
-    ee_delegate(desc, ?EXTRA_SCHEMA_MODULES ++ ?EE_SCHEMA_MODULES, Name).
+    ee_delegate(desc, ee_mods(), Name).
 
 
 validations() ->
 validations() ->
     emqx_conf_schema:validations() ++ emqx_license_schema:validations().
     emqx_conf_schema:validations() ++ emqx_license_schema:validations().
@@ -144,9 +144,11 @@ ee_roots() ->
         fun(Module) ->
         fun(Module) ->
             apply(Module, roots, [])
             apply(Module, roots, [])
         end,
         end,
-        ?EXTRA_SCHEMA_MODULES ++ ?EE_SCHEMA_MODULES
+        ee_mods()
     ).
     ).
 
 
+ee_mods() -> ?EXTRA_SCHEMA_MODULES ++ ?EE_SCHEMA_MODULES.
+
 ee_delegate(Method, [EEMod | EEMods], Name) ->
 ee_delegate(Method, [EEMod | EEMods], Name) ->
     case lists:member(Name, apply(EEMod, roots, [])) of
     case lists:member(Name, apply(EEMod, roots, [])) of
         true ->
         true ->

+ 9 - 8
apps/emqx_enterprise/test/emqx_enterprise_schema_tests.erl

@@ -57,8 +57,8 @@ injected_roots_test() ->
     InjectedRoots = lists:usort([Root || {Root, _Sc} <- emqx_enterprise_schema:roots()]),
     InjectedRoots = lists:usort([Root || {Root, _Sc} <- emqx_enterprise_schema:roots()]),
     MissingRoots = ExpectedRoots -- InjectedRoots,
     MissingRoots = ExpectedRoots -- InjectedRoots,
     ?assertEqual([], MissingRoots, #{
     ?assertEqual([], MissingRoots, #{
-        expected_roots => ExpectedRoots,
-        injected_roots => InjectedRoots,
+        missing => ExpectedRoots -- InjectedRoots,
+        unknown => InjectedRoots -- ExpectedRoots,
         hint =>
         hint =>
             <<
             <<
                 "maybe there's a missing schema module to be added to"
                 "maybe there's a missing schema module to be added to"
@@ -69,11 +69,15 @@ injected_roots_test() ->
     ok.
     ok.
 
 
 ee_schema_roots() ->
 ee_schema_roots() ->
+    #{ee_business_apps := Apps} = emqx_machine_boot:read_apps(),
+    lists:append([ee_schema_roots(atom_to_list(App)) || App <- Apps]).
+
+ee_schema_roots(AppName) ->
     lists:foldl(
     lists:foldl(
         fun(Filepath, Acc) ->
         fun(Filepath, Acc) ->
-            ["apps", App | _] = filename:split(Filepath),
+            ["apps", _App | _] = filename:split(Filepath),
             Mod = module(Filepath),
             Mod = module(Filepath),
-            case is_ee(App) andalso has_roots(Mod) of
+            case has_roots(Mod) of
                 true ->
                 true ->
                     Roots = [Root || {Root, _Sc} <- Mod:roots()],
                     Roots = [Root || {Root, _Sc} <- Mod:roots()],
                     Roots ++ Acc;
                     Roots ++ Acc;
@@ -82,12 +86,9 @@ ee_schema_roots() ->
             end
             end
         end,
         end,
         [],
         [],
-        filelib:wildcard("apps/*/src/**/*_schema.erl")
+        filelib:wildcard("apps/" ++ AppName ++ "/src/**/*_schema.erl")
     ).
     ).
 
 
-is_ee(App) ->
-    filelib:is_file(filename:join(["apps", App, "BSL.txt"])).
-
 module(Filepath) ->
 module(Filepath) ->
     ModStr = filename:basename(Filepath, ".erl"),
     ModStr = filename:basename(Filepath, ".erl"),
     list_to_atom(ModStr).
     list_to_atom(ModStr).

+ 1 - 1
apps/emqx_machine/src/emqx_machine.app.src

@@ -3,7 +3,7 @@
     {id, "emqx_machine"},
     {id, "emqx_machine"},
     {description, "The EMQX Machine"},
     {description, "The EMQX Machine"},
     % strict semver, bump manually!
     % strict semver, bump manually!
-    {vsn, "0.3.4"},
+    {vsn, "0.3.5"},
     {modules, []},
     {modules, []},
     {registered, []},
     {registered, []},
     {applications, [kernel, stdlib, emqx_ctl, redbug]},
     {applications, [kernel, stdlib, emqx_ctl, redbug]},

+ 13 - 9
apps/emqx_machine/src/emqx_machine_boot.erl

@@ -23,6 +23,7 @@
 -export([sorted_reboot_apps/0]).
 -export([sorted_reboot_apps/0]).
 -export([start_autocluster/0]).
 -export([start_autocluster/0]).
 -export([stop_port_apps/0]).
 -export([stop_port_apps/0]).
+-export([read_apps/0]).
 
 
 -dialyzer({no_match, [basic_reboot_apps/0]}).
 -dialyzer({no_match, [basic_reboot_apps/0]}).
 
 
@@ -134,15 +135,11 @@ reboot_apps() ->
     BaseRebootApps ++ ConfigApps.
     BaseRebootApps ++ ConfigApps.
 
 
 basic_reboot_apps() ->
 basic_reboot_apps() ->
-    PrivDir = code:priv_dir(emqx_machine),
-    RebootListPath = filename:join([PrivDir, "reboot_lists.eterm"]),
-    {ok, [
-        #{
-            common_business_apps := CommonBusinessApps,
-            ee_business_apps := EEBusinessApps,
-            ce_business_apps := CEBusinessApps
-        }
-    ]} = file:consult(RebootListPath),
+    #{
+        common_business_apps := CommonBusinessApps,
+        ee_business_apps := EEBusinessApps,
+        ce_business_apps := CEBusinessApps
+    } = read_apps(),
     EditionSpecificApps =
     EditionSpecificApps =
         case emqx_release:edition() of
         case emqx_release:edition() of
             ee -> EEBusinessApps;
             ee -> EEBusinessApps;
@@ -152,6 +149,13 @@ basic_reboot_apps() ->
     BusinessApps = CommonBusinessApps ++ EditionSpecificApps,
     BusinessApps = CommonBusinessApps ++ EditionSpecificApps,
     ?BASIC_REBOOT_APPS ++ (BusinessApps -- excluded_apps()).
     ?BASIC_REBOOT_APPS ++ (BusinessApps -- excluded_apps()).
 
 
+%% @doc Read business apps belonging to the current profile/edition.
+read_apps() ->
+    PrivDir = code:priv_dir(emqx_machine),
+    RebootListPath = filename:join([PrivDir, "reboot_lists.eterm"]),
+    {ok, [Apps]} = file:consult(RebootListPath),
+    Apps.
+
 excluded_apps() ->
 excluded_apps() ->
     %% Optional apps _should_ be (re)started automatically, but only
     %% Optional apps _should_ be (re)started automatically, but only
     %% when they are found in the release:
     %% when they are found in the release: