|
|
@@ -54,7 +54,7 @@ ensure_acl_conf() ->
|
|
|
|
|
|
injected_roots_test() ->
|
|
|
ExpectedRoots = lists:usort(ee_schema_roots()),
|
|
|
- InjectedRoots = lists:usort([Root || {Root, _Sc} <- emqx_enterprise_schema:roots()]),
|
|
|
+ InjectedRoots = lists:usort(get_roots(emqx_enterprise_schema)),
|
|
|
MissingRoots = ExpectedRoots -- InjectedRoots,
|
|
|
?assertEqual([], MissingRoots, #{
|
|
|
missing => ExpectedRoots -- InjectedRoots,
|
|
|
@@ -75,12 +75,10 @@ ee_schema_roots() ->
|
|
|
ee_schema_roots(AppName) ->
|
|
|
lists:foldl(
|
|
|
fun(Filepath, Acc) ->
|
|
|
- ["apps", _App | _] = filename:split(Filepath),
|
|
|
Mod = module(Filepath),
|
|
|
case has_roots(Mod) of
|
|
|
true ->
|
|
|
- Roots = [Root || {Root, _Sc} <- Mod:roots()],
|
|
|
- Roots ++ Acc;
|
|
|
+ get_roots(Mod) ++ Acc;
|
|
|
false ->
|
|
|
Acc
|
|
|
end
|
|
|
@@ -93,7 +91,25 @@ module(Filepath) ->
|
|
|
ModStr = filename:basename(Filepath, ".erl"),
|
|
|
list_to_atom(ModStr).
|
|
|
|
|
|
+get_roots(Mod) ->
|
|
|
+ lists:map(
|
|
|
+ fun
|
|
|
+ ({Root, _Sc}) ->
|
|
|
+ Root;
|
|
|
+ (Root) when is_atom(Root) ->
|
|
|
+ Root
|
|
|
+ end,
|
|
|
+ Mod:roots()
|
|
|
+ ).
|
|
|
+
|
|
|
has_roots(Mod) ->
|
|
|
- _ = Mod:module_info(),
|
|
|
- erlang:function_exported(Mod, roots, 0) andalso
|
|
|
- Mod:roots() =/= [].
|
|
|
+ try
|
|
|
+ _ = Mod:module_info(),
|
|
|
+ erlang:function_exported(Mod, roots, 0) andalso
|
|
|
+ Mod:roots() =/= []
|
|
|
+ catch
|
|
|
+ error:undef ->
|
|
|
+ %% may have picked a module from an app that's not in the enterprise release.
|
|
|
+ ct:pal("module not found? ~s", [Mod]),
|
|
|
+ false
|
|
|
+ end.
|