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

Merge pull request #13723 from thalesmg/20240829-r58-another-schema-test-fix

test(schema): handle single atom roots
Thales Macedo Garitezi пре 1 година
родитељ
комит
4ddf093255

+ 23 - 7
apps/emqx_enterprise/test/emqx_enterprise_schema_tests.erl

@@ -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.

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

@@ -1,6 +1,6 @@
 {application, emqx_s3, [
     {description, "EMQX S3"},
-    {vsn, "5.1.1"},
+    {vsn, "5.1.2"},
     {modules, []},
     {registered, [emqx_s3_sup]},
     {applications, [

+ 1 - 1
apps/emqx_s3/src/emqx_s3_schema.erl

@@ -16,7 +16,7 @@
 -export([translate/2]).
 
 roots() ->
-    [s3].
+    [].
 
 namespace() -> "s3".