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

test: avoid stopping cover and using meck

Thales Macedo Garitezi пре 3 година
родитељ
комит
7e6b94fc12

+ 7 - 0
lib-ee/emqx_license/src/emqx_license_parser.erl

@@ -72,9 +72,16 @@
 %% API
 %%--------------------------------------------------------------------
 
+-ifdef(TEST).
+-spec parse(string() | binary()) -> {ok, license()} | {error, term()}.
+parse(Content) ->
+    PubKey = persistent_term:get({emqx_license_parser_test, pubkey}, ?PUBKEY),
+    parse(Content, PubKey).
+-else.
 -spec parse(string() | binary()) -> {ok, license()} | {error, term()}.
 parse(Content) ->
     parse(Content, ?PUBKEY).
+-endif.
 
 parse(Content, Pem) ->
     [PemEntry] = public_key:pem_decode(Pem),

+ 3 - 15
lib-ee/emqx_license/test/emqx_license_SUITE.erl

@@ -16,9 +16,6 @@ all() ->
     emqx_common_test_helpers:all(?MODULE).
 
 init_per_suite(Config) ->
-    %% hack needed to avoid inter-suite flakiness when using meck...
-    ok = cover:stop(),
-    {ok, _} = cover:start(),
     _ = application:load(emqx_conf),
     emqx_config:save_schema_mod_and_names(emqx_license_schema),
     emqx_common_test_helpers:start_apps([emqx_license], fun set_special_configs/1),
@@ -144,18 +141,9 @@ setup_test(TestCase, Config) when
                     emqx_config:put([license], LicConfig),
                     RawConfig = #{<<"type">> => file, <<"file">> => LicensePath},
                     emqx_config:put_raw([<<"license">>], RawConfig),
-                    ok = meck:new(emqx_license_parser, [
-                        non_strict, passthrough, no_history, no_link
-                    ]),
-                    meck:expect(
-                        emqx_license_parser,
-                        parse,
-                        fun(X) ->
-                            emqx_license_parser:parse(
-                                X,
-                                emqx_license_test_lib:public_key_pem()
-                            )
-                        end
+                    ok = persistent_term:put(
+                        {emqx_license_parser_test, pubkey},
+                        emqx_license_test_lib:public_key_pem()
                     ),
                     ok;
                 (_) ->

+ 4 - 11
lib-ee/emqx_license/test/emqx_license_http_api_SUITE.erl

@@ -25,12 +25,12 @@ init_per_suite(Config) ->
     Config.
 
 end_per_suite(_) ->
-    ok = meck:unload([emqx_license_parser]),
     emqx_common_test_helpers:stop_apps([emqx_license, emqx_dashboard]),
     Config = #{type => file, file => emqx_license_test_lib:default_license()},
     emqx_config:put([license], Config),
     RawConfig = #{<<"type">> => file, <<"file">> => emqx_license_test_lib:default_license()},
     emqx_config:put_raw([<<"license">>], RawConfig),
+    persistent_term:erase({emqx_license_parser_test, pubkey}),
     ok.
 
 set_special_configs(emqx_dashboard) ->
@@ -41,16 +41,9 @@ set_special_configs(emqx_license) ->
     emqx_config:put([license], Config),
     RawConfig = #{<<"type">> => key, <<"key">> => LicenseKey},
     emqx_config:put_raw([<<"license">>], RawConfig),
-    ok = meck:new(emqx_license_parser, [non_strict, passthrough, no_history, no_link]),
-    ok = meck:expect(
-        emqx_license_parser,
-        parse,
-        fun(X) ->
-            emqx_license_parser:parse(
-                X,
-                emqx_license_test_lib:public_key_pem()
-            )
-        end
+    ok = persistent_term:put(
+        {emqx_license_parser_test, pubkey},
+        emqx_license_test_lib:public_key_pem()
     ),
     ok;
 set_special_configs(_) ->