refactor(config): remove emqx:get_env/1,2 from testcases

This commit is contained in:
Shawn 2021-07-22 16:01:05 +08:00
parent 0a3b77f65d
commit f2e62def1b
10 changed files with 3 additions and 40 deletions

View File

@ -31,23 +31,13 @@ all() ->
init_per_suite(Config) -> init_per_suite(Config) ->
application:set_env(ekka, strict_mode, true), application:set_env(ekka, strict_mode, true),
emqx_ct_helpers:start_apps([emqx_authn], fun set_special_configs/1), emqx_ct_helpers:start_apps([emqx_authn]),
Config. Config.
end_per_suite(_) -> end_per_suite(_) ->
file:delete(filename:join(emqx:get_env(plugins_etc_dir), 'emqx_authn.conf')),
emqx_ct_helpers:stop_apps([emqx_authn]), emqx_ct_helpers:stop_apps([emqx_authn]),
ok. ok.
set_special_configs(emqx_authn) ->
application:set_env(emqx, plugins_etc_dir,
emqx_ct_helpers:deps_path(emqx_authn, "test")),
Conf = #{<<"emqx_authn">> => #{<<"authenticators">> => [], <<"enable">> => false}},
ok = file:write_file(filename:join(emqx:get_env(plugins_etc_dir), 'emqx_authn.conf'), jsx:encode(Conf)),
ok;
set_special_configs(_App) ->
ok.
t_chain(_) -> t_chain(_) ->
?assertMatch({ok, #{id := ?CHAIN, authenticators := []}}, ?AUTH:lookup_chain(?CHAIN)), ?assertMatch({ok, #{id := ?CHAIN, authenticators := []}}, ?AUTH:lookup_chain(?CHAIN)),

View File

@ -30,23 +30,13 @@ all() ->
emqx_ct:all(?MODULE). emqx_ct:all(?MODULE).
init_per_suite(Config) -> init_per_suite(Config) ->
emqx_ct_helpers:start_apps([emqx_authn], fun set_special_configs/1), emqx_ct_helpers:start_apps([emqx_authn]),
Config. Config.
end_per_suite(_) -> end_per_suite(_) ->
file:delete(filename:join(emqx:get_env(plugins_etc_dir), 'emqx_authn.conf')),
emqx_ct_helpers:stop_apps([emqx_authn]), emqx_ct_helpers:stop_apps([emqx_authn]),
ok. ok.
set_special_configs(emqx_authn) ->
application:set_env(emqx, plugins_etc_dir,
emqx_ct_helpers:deps_path(emqx_authn, "test")),
Conf = #{<<"emqx_authn">> => #{<<"authenticators">> => [], <<"enable">> => false}},
ok = file:write_file(filename:join(emqx:get_env(plugins_etc_dir), 'emqx_authn.conf'), jsx:encode(Conf)),
ok;
set_special_configs(_App) ->
ok.
t_jwt_authenticator(_) -> t_jwt_authenticator(_) ->
AuthenticatorName = <<"myauthenticator">>, AuthenticatorName = <<"myauthenticator">>,
Config = #{use_jwks => false, Config = #{use_jwks => false,

View File

@ -30,23 +30,13 @@ all() ->
emqx_ct:all(?MODULE). emqx_ct:all(?MODULE).
init_per_suite(Config) -> init_per_suite(Config) ->
emqx_ct_helpers:start_apps([emqx_authn], fun set_special_configs/1), emqx_ct_helpers:start_apps([emqx_authn]),
Config. Config.
end_per_suite(_) -> end_per_suite(_) ->
file:delete(filename:join(emqx:get_env(plugins_etc_dir), 'emqx_authn.conf')),
emqx_ct_helpers:stop_apps([emqx_authn]), emqx_ct_helpers:stop_apps([emqx_authn]),
ok. ok.
set_special_configs(emqx_authn) ->
application:set_env(emqx, plugins_etc_dir,
emqx_ct_helpers:deps_path(emqx_authn, "test")),
Conf = #{<<"emqx_authn">> => #{<<"authenticators">> => [], <<"enable">> => false}},
ok = file:write_file(filename:join(emqx:get_env(plugins_etc_dir), 'emqx_authn.conf'), jsx:encode(Conf)),
ok;
set_special_configs(_App) ->
ok.
t_mnesia_authenticator(_) -> t_mnesia_authenticator(_) ->
AuthenticatorName = <<"myauthenticator">>, AuthenticatorName = <<"myauthenticator">>,
AuthenticatorConfig = #{name => AuthenticatorName, AuthenticatorConfig = #{name => AuthenticatorName,

View File

@ -36,7 +36,6 @@ init_per_suite(Config) ->
Config. Config.
end_per_suite(_Config) -> end_per_suite(_Config) ->
file:delete(filename:join(emqx:get_env(plugins_etc_dir), 'authz.conf')),
emqx_ct_helpers:stop_apps([emqx_authz]). emqx_ct_helpers:stop_apps([emqx_authz]).
-define(RULE1, #{principal => all, -define(RULE1, #{principal => all,

View File

@ -53,7 +53,6 @@ init_per_suite(Config) ->
end_per_suite(_Config) -> end_per_suite(_Config) ->
%delete_default_app(), %delete_default_app(),
file:delete(filename:join(emqx:get_env(plugins_etc_dir), 'authz.conf')),
meck:unload(emqx_schema), meck:unload(emqx_schema),
emqx_ct_helpers:stop_apps([emqx_authz]). emqx_ct_helpers:stop_apps([emqx_authz]).

View File

@ -51,7 +51,6 @@ init_per_suite(Config) ->
Config. Config.
end_per_suite(_Config) -> end_per_suite(_Config) ->
file:delete(filename:join(emqx:get_env(plugins_etc_dir), 'authz.conf')),
emqx_ct_helpers:stop_apps([emqx_authz, emqx_resource]), emqx_ct_helpers:stop_apps([emqx_authz, emqx_resource]),
meck:unload(emqx_schema), meck:unload(emqx_schema),
meck:unload(emqx_resource). meck:unload(emqx_resource).

View File

@ -55,7 +55,6 @@ init_per_suite(Config) ->
Config. Config.
end_per_suite(_Config) -> end_per_suite(_Config) ->
file:delete(filename:join(emqx:get_env(plugins_etc_dir), 'authz.conf')),
emqx_ct_helpers:stop_apps([emqx_authz, emqx_resource]), emqx_ct_helpers:stop_apps([emqx_authz, emqx_resource]),
meck:unload(emqx_schema), meck:unload(emqx_schema),
meck:unload(emqx_resource). meck:unload(emqx_resource).

View File

@ -54,7 +54,6 @@ init_per_suite(Config) ->
Config. Config.
end_per_suite(_Config) -> end_per_suite(_Config) ->
file:delete(filename:join(emqx:get_env(plugins_etc_dir), 'authz.conf')),
emqx_ct_helpers:stop_apps([emqx_authz, emqx_resource]), emqx_ct_helpers:stop_apps([emqx_authz, emqx_resource]),
meck:unload(emqx_schema), meck:unload(emqx_schema),
meck:unload(emqx_resource). meck:unload(emqx_resource).

View File

@ -53,7 +53,6 @@ init_per_suite(Config) ->
Config. Config.
end_per_suite(_Config) -> end_per_suite(_Config) ->
file:delete(filename:join(emqx:get_env(plugins_etc_dir), 'authz.conf')),
emqx_ct_helpers:stop_apps([emqx_authz, emqx_resource]), emqx_ct_helpers:stop_apps([emqx_authz, emqx_resource]),
meck:unload(emqx_schema), meck:unload(emqx_schema),
meck:unload(emqx_resource). meck:unload(emqx_resource).

View File

@ -52,7 +52,6 @@ init_per_suite(Config) ->
Config. Config.
end_per_suite(_Config) -> end_per_suite(_Config) ->
file:delete(filename:join(emqx:get_env(plugins_etc_dir), 'authz.conf')),
emqx_ct_helpers:stop_apps([emqx_authz, emqx_resource]), emqx_ct_helpers:stop_apps([emqx_authz, emqx_resource]),
meck:unload(emqx_schema), meck:unload(emqx_schema),
meck:unload(emqx_resource). meck:unload(emqx_resource).