test: avoid stopping cover and using meck
This commit is contained in:
parent
69ec76f586
commit
7e6b94fc12
|
@ -72,9 +72,16 @@
|
||||||
%% API
|
%% 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()}.
|
-spec parse(string() | binary()) -> {ok, license()} | {error, term()}.
|
||||||
parse(Content) ->
|
parse(Content) ->
|
||||||
parse(Content, ?PUBKEY).
|
parse(Content, ?PUBKEY).
|
||||||
|
-endif.
|
||||||
|
|
||||||
parse(Content, Pem) ->
|
parse(Content, Pem) ->
|
||||||
[PemEntry] = public_key:pem_decode(Pem),
|
[PemEntry] = public_key:pem_decode(Pem),
|
||||||
|
|
|
@ -16,9 +16,6 @@ all() ->
|
||||||
emqx_common_test_helpers:all(?MODULE).
|
emqx_common_test_helpers:all(?MODULE).
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
%% hack needed to avoid inter-suite flakiness when using meck...
|
|
||||||
ok = cover:stop(),
|
|
||||||
{ok, _} = cover:start(),
|
|
||||||
_ = application:load(emqx_conf),
|
_ = application:load(emqx_conf),
|
||||||
emqx_config:save_schema_mod_and_names(emqx_license_schema),
|
emqx_config:save_schema_mod_and_names(emqx_license_schema),
|
||||||
emqx_common_test_helpers:start_apps([emqx_license], fun set_special_configs/1),
|
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),
|
emqx_config:put([license], LicConfig),
|
||||||
RawConfig = #{<<"type">> => file, <<"file">> => LicensePath},
|
RawConfig = #{<<"type">> => file, <<"file">> => LicensePath},
|
||||||
emqx_config:put_raw([<<"license">>], RawConfig),
|
emqx_config:put_raw([<<"license">>], RawConfig),
|
||||||
ok = meck:new(emqx_license_parser, [
|
ok = persistent_term:put(
|
||||||
non_strict, passthrough, no_history, no_link
|
{emqx_license_parser_test, pubkey},
|
||||||
]),
|
|
||||||
meck:expect(
|
|
||||||
emqx_license_parser,
|
|
||||||
parse,
|
|
||||||
fun(X) ->
|
|
||||||
emqx_license_parser:parse(
|
|
||||||
X,
|
|
||||||
emqx_license_test_lib:public_key_pem()
|
emqx_license_test_lib:public_key_pem()
|
||||||
)
|
|
||||||
end
|
|
||||||
),
|
),
|
||||||
ok;
|
ok;
|
||||||
(_) ->
|
(_) ->
|
||||||
|
|
|
@ -25,12 +25,12 @@ init_per_suite(Config) ->
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_) ->
|
end_per_suite(_) ->
|
||||||
ok = meck:unload([emqx_license_parser]),
|
|
||||||
emqx_common_test_helpers:stop_apps([emqx_license, emqx_dashboard]),
|
emqx_common_test_helpers:stop_apps([emqx_license, emqx_dashboard]),
|
||||||
Config = #{type => file, file => emqx_license_test_lib:default_license()},
|
Config = #{type => file, file => emqx_license_test_lib:default_license()},
|
||||||
emqx_config:put([license], Config),
|
emqx_config:put([license], Config),
|
||||||
RawConfig = #{<<"type">> => file, <<"file">> => emqx_license_test_lib:default_license()},
|
RawConfig = #{<<"type">> => file, <<"file">> => emqx_license_test_lib:default_license()},
|
||||||
emqx_config:put_raw([<<"license">>], RawConfig),
|
emqx_config:put_raw([<<"license">>], RawConfig),
|
||||||
|
persistent_term:erase({emqx_license_parser_test, pubkey}),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
set_special_configs(emqx_dashboard) ->
|
set_special_configs(emqx_dashboard) ->
|
||||||
|
@ -41,16 +41,9 @@ set_special_configs(emqx_license) ->
|
||||||
emqx_config:put([license], Config),
|
emqx_config:put([license], Config),
|
||||||
RawConfig = #{<<"type">> => key, <<"key">> => LicenseKey},
|
RawConfig = #{<<"type">> => key, <<"key">> => LicenseKey},
|
||||||
emqx_config:put_raw([<<"license">>], RawConfig),
|
emqx_config:put_raw([<<"license">>], RawConfig),
|
||||||
ok = meck:new(emqx_license_parser, [non_strict, passthrough, no_history, no_link]),
|
ok = persistent_term:put(
|
||||||
ok = meck:expect(
|
{emqx_license_parser_test, pubkey},
|
||||||
emqx_license_parser,
|
|
||||||
parse,
|
|
||||||
fun(X) ->
|
|
||||||
emqx_license_parser:parse(
|
|
||||||
X,
|
|
||||||
emqx_license_test_lib:public_key_pem()
|
emqx_license_test_lib:public_key_pem()
|
||||||
)
|
|
||||||
end
|
|
||||||
),
|
),
|
||||||
ok;
|
ok;
|
||||||
set_special_configs(_) ->
|
set_special_configs(_) ->
|
||||||
|
|
Loading…
Reference in New Issue