test(license): update and simplify tests
This commit is contained in:
parent
24dfa41722
commit
0a9cbe3080
|
@ -17,121 +17,32 @@ all() ->
|
|||
|
||||
init_per_suite(Config) ->
|
||||
emqx_license_test_lib:mock_parser(),
|
||||
_ = 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),
|
||||
Config.
|
||||
Apps = emqx_cth_suite:start(
|
||||
[
|
||||
emqx,
|
||||
emqx_conf,
|
||||
{emqx_license, "license { key = \"default\" }"}
|
||||
],
|
||||
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
||||
),
|
||||
[{suite_apps, Apps} | Config].
|
||||
|
||||
end_per_suite(_) ->
|
||||
end_per_suite(Config) ->
|
||||
emqx_license_test_lib:unmock_parser(),
|
||||
emqx_common_test_helpers:stop_apps([emqx_license]),
|
||||
ok.
|
||||
ok = emqx_cth_suite:stop(?config(suite_apps, Config)).
|
||||
|
||||
init_per_testcase(Case, Config) ->
|
||||
{ok, _} = emqx_cluster_rpc:start_link(node(), emqx_cluster_rpc, 1000),
|
||||
Paths = set_override_paths(Case),
|
||||
Config0 = setup_test(Case, Config),
|
||||
Paths ++ Config0 ++ Config.
|
||||
setup_test(Case, Config) ++ Config.
|
||||
|
||||
end_per_testcase(Case, Config) ->
|
||||
clean_overrides(Case, Config),
|
||||
teardown_test(Case, Config),
|
||||
ok.
|
||||
teardown_test(Case, Config).
|
||||
|
||||
set_override_paths(_TestCase) ->
|
||||
[].
|
||||
|
||||
clean_overrides(_TestCase, _Config) ->
|
||||
ok.
|
||||
|
||||
setup_test(TestCase, Config) when
|
||||
TestCase =:= t_update_file_cluster_backup
|
||||
->
|
||||
DataDir = ?config(data_dir, Config),
|
||||
{LicenseKey, _License} = mk_license(
|
||||
[
|
||||
%% license format version
|
||||
"220111",
|
||||
%% license type
|
||||
"0",
|
||||
%% customer type
|
||||
"10",
|
||||
%% customer name
|
||||
"Foo",
|
||||
%% customer email
|
||||
"contact@foo.com",
|
||||
%% deplayment name
|
||||
"bar-deployment",
|
||||
%% start date
|
||||
"20220111",
|
||||
%% days
|
||||
"100000",
|
||||
%% max connections
|
||||
"19"
|
||||
]
|
||||
),
|
||||
Cluster = emqx_common_test_helpers:emqx_cluster(
|
||||
[core, core],
|
||||
[
|
||||
{apps, [emqx_conf, emqx_license]},
|
||||
{load_schema, false},
|
||||
{schema_mod, emqx_enterprise_schema},
|
||||
{env_handler, fun
|
||||
(emqx) ->
|
||||
emqx_config:save_schema_mod_and_names(emqx_enterprise_schema),
|
||||
%% emqx_config:save_schema_mod_and_names(emqx_license_schema),
|
||||
application:set_env(emqx, boot_modules, []),
|
||||
application:set_env(
|
||||
emqx,
|
||||
data_dir,
|
||||
filename:join([
|
||||
DataDir,
|
||||
TestCase,
|
||||
node()
|
||||
])
|
||||
),
|
||||
ok;
|
||||
(emqx_conf) ->
|
||||
emqx_config:save_schema_mod_and_names(emqx_enterprise_schema),
|
||||
%% emqx_config:save_schema_mod_and_names(emqx_license_schema),
|
||||
application:set_env(
|
||||
emqx,
|
||||
data_dir,
|
||||
filename:join([
|
||||
DataDir,
|
||||
TestCase,
|
||||
node()
|
||||
])
|
||||
),
|
||||
ok;
|
||||
(emqx_license) ->
|
||||
set_special_configs(emqx_license),
|
||||
ok;
|
||||
(_) ->
|
||||
ok
|
||||
end}
|
||||
]
|
||||
),
|
||||
Nodes = [emqx_common_test_helpers:start_peer(Name, Opts) || {Name, Opts} <- Cluster],
|
||||
[{nodes, Nodes}, {cluster, Cluster}, {old_license, LicenseKey}];
|
||||
setup_test(_TestCase, _Config) ->
|
||||
[].
|
||||
|
||||
teardown_test(_TestCase, _Config) ->
|
||||
ok.
|
||||
|
||||
set_special_configs(emqx_license) ->
|
||||
Config = #{key => default},
|
||||
emqx_config:put([license], Config),
|
||||
RawConfig = #{<<"key">> => <<"default">>},
|
||||
emqx_config:put_raw([<<"license">>], RawConfig);
|
||||
set_special_configs(_) ->
|
||||
ok.
|
||||
|
||||
assert_on_nodes(Nodes, RunFun, CheckFun) ->
|
||||
Res = [{N, erpc:call(N, RunFun)} || N <- Nodes],
|
||||
lists:foreach(CheckFun, Res).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% Tests
|
||||
%%------------------------------------------------------------------------------
|
||||
|
|
|
@ -14,34 +14,35 @@
|
|||
all() ->
|
||||
emqx_common_test_helpers:all(?MODULE).
|
||||
|
||||
init_per_suite(CtConfig) ->
|
||||
_ = application:load(emqx_conf),
|
||||
init_per_suite(Config) ->
|
||||
emqx_license_test_lib:mock_parser(),
|
||||
ok = emqx_common_test_helpers:start_apps([emqx_license], fun set_special_configs/1),
|
||||
CtConfig.
|
||||
Apps = emqx_cth_suite:start(
|
||||
[
|
||||
emqx,
|
||||
emqx_conf,
|
||||
{emqx_license, #{
|
||||
config => #{license => #{key => emqx_license_test_lib:default_test_license()}}
|
||||
}}
|
||||
],
|
||||
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
||||
),
|
||||
[{suite_apps, Apps} | Config].
|
||||
|
||||
end_per_suite(_) ->
|
||||
end_per_suite(Config) ->
|
||||
emqx_license_test_lib:unmock_parser(),
|
||||
ok = emqx_common_test_helpers:stop_apps([emqx_license]).
|
||||
ok = emqx_cth_suite:stop(?config(suite_apps, Config)).
|
||||
|
||||
init_per_testcase(t_default_limits, Config) ->
|
||||
ok = emqx_common_test_helpers:stop_apps([emqx_license]),
|
||||
ok = application:stop(emqx_license),
|
||||
Config;
|
||||
init_per_testcase(_Case, Config) ->
|
||||
{ok, _} = emqx_cluster_rpc:start_link(node(), emqx_cluster_rpc, 1000),
|
||||
Config.
|
||||
|
||||
end_per_testcase(t_default_limits, _Config) ->
|
||||
ok = emqx_common_test_helpers:start_apps([emqx_license], fun set_special_configs/1);
|
||||
{ok, _} = application:ensure_all_started(emqx_license);
|
||||
end_per_testcase(_Case, _Config) ->
|
||||
ok.
|
||||
|
||||
set_special_configs(emqx_license) ->
|
||||
Config = #{key => emqx_license_test_lib:default_test_license()},
|
||||
emqx_config:put([license], Config);
|
||||
set_special_configs(_) ->
|
||||
ok.
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% Tests
|
||||
%%------------------------------------------------------------------------------
|
||||
|
|
|
@ -14,32 +14,29 @@ all() ->
|
|||
emqx_common_test_helpers:all(?MODULE).
|
||||
|
||||
init_per_suite(Config) ->
|
||||
_ = 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),
|
||||
Config.
|
||||
Apps = emqx_cth_suite:start(
|
||||
[
|
||||
emqx,
|
||||
emqx_conf,
|
||||
{emqx_license, #{
|
||||
config => #{license => #{key => emqx_license_test_lib:default_license()}}
|
||||
}}
|
||||
],
|
||||
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
||||
),
|
||||
[{suite_apps, Apps} | Config].
|
||||
|
||||
end_per_suite(_) ->
|
||||
emqx_common_test_helpers:stop_apps([emqx_license]),
|
||||
ok.
|
||||
end_per_suite(Config) ->
|
||||
ok = emqx_cth_suite:stop(?config(suite_apps, Config)).
|
||||
|
||||
init_per_testcase(_Case, Config) ->
|
||||
emqx_license_test_lib:mock_parser(),
|
||||
{ok, _} = emqx_cluster_rpc:start_link(node(), emqx_cluster_rpc, 1000),
|
||||
Config.
|
||||
|
||||
end_per_testcase(_Case, _Config) ->
|
||||
emqx_license_test_lib:unmock_parser(),
|
||||
ok.
|
||||
|
||||
set_special_configs(emqx_license) ->
|
||||
Config = #{key => emqx_license_test_lib:default_license()},
|
||||
emqx_config:put([license], Config),
|
||||
RawConfig = #{<<"key">> => emqx_license_test_lib:default_license()},
|
||||
emqx_config:put_raw([<<"license">>], RawConfig);
|
||||
set_special_configs(_) ->
|
||||
ok.
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% Tests
|
||||
%%------------------------------------------------------------------------------
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
-compile(nowarn_export_all).
|
||||
-compile(export_all).
|
||||
|
||||
-include_lib("emqx/include/emqx_mqtt.hrl").
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include_lib("common_test/include/ct.hrl").
|
||||
|
||||
|
@ -20,41 +19,34 @@ all() ->
|
|||
|
||||
init_per_suite(Config) ->
|
||||
emqx_license_test_lib:mock_parser(),
|
||||
_ = application:load(emqx_conf),
|
||||
emqx_config:save_schema_mod_and_names(emqx_license_schema),
|
||||
emqx_common_test_helpers:start_apps([emqx_license, emqx_dashboard], fun set_special_configs/1),
|
||||
Config.
|
||||
Apps = emqx_cth_suite:start(
|
||||
[
|
||||
emqx,
|
||||
emqx_conf,
|
||||
{emqx_license, #{
|
||||
config => #{
|
||||
license => #{
|
||||
key => emqx_license_test_lib:make_license(#{max_connections => "100"}),
|
||||
connection_low_watermark => <<"75%">>,
|
||||
connection_high_watermark => <<"80%">>
|
||||
}
|
||||
}
|
||||
}},
|
||||
{emqx_dashboard,
|
||||
"dashboard {"
|
||||
"\n listeners.http { enable = true, bind = 18083 }"
|
||||
"\n default_username = \"license_admin\""
|
||||
"\n}"}
|
||||
],
|
||||
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
||||
),
|
||||
[{suite_apps, Apps} | Config].
|
||||
|
||||
end_per_suite(_) ->
|
||||
emqx_common_test_helpers:stop_apps([emqx_license, emqx_dashboard]),
|
||||
LicenseKey = emqx_license_test_lib:make_license(#{max_connections => "100"}),
|
||||
Config = #{key => LicenseKey},
|
||||
emqx_config:put([license], Config),
|
||||
RawConfig = #{<<"key">> => LicenseKey},
|
||||
emqx_config:put_raw([<<"license">>], RawConfig),
|
||||
end_per_suite(Config) ->
|
||||
emqx_license_test_lib:unmock_parser(),
|
||||
ok.
|
||||
|
||||
set_special_configs(emqx_dashboard) ->
|
||||
emqx_dashboard_api_test_helpers:set_default_config(<<"license_admin">>);
|
||||
set_special_configs(emqx_license) ->
|
||||
LicenseKey = emqx_license_test_lib:make_license(#{max_connections => "100"}),
|
||||
Config = #{
|
||||
key => LicenseKey, connection_low_watermark => 0.75, connection_high_watermark => 0.8
|
||||
},
|
||||
emqx_config:put([license], Config),
|
||||
RawConfig = #{
|
||||
<<"key">> => LicenseKey,
|
||||
<<"connection_low_watermark">> => <<"75%">>,
|
||||
<<"connection_high_watermark">> => <<"80%">>
|
||||
},
|
||||
emqx_config:put_raw([<<"license">>], RawConfig),
|
||||
ok;
|
||||
set_special_configs(_) ->
|
||||
ok.
|
||||
ok = emqx_cth_suite:stop(?config(suite_apps, Config)).
|
||||
|
||||
init_per_testcase(_TestCase, Config) ->
|
||||
{ok, _} = emqx_cluster_rpc:start_link(node(), emqx_cluster_rpc, 1000),
|
||||
Config.
|
||||
|
||||
end_per_testcase(_TestCase, _Config) ->
|
||||
|
|
|
@ -14,26 +14,20 @@ all() ->
|
|||
emqx_common_test_helpers:all(?MODULE).
|
||||
|
||||
init_per_suite(Config) ->
|
||||
_ = application:load(emqx_conf),
|
||||
emqx_common_test_helpers:start_apps([emqx_license], fun set_special_configs/1),
|
||||
Config.
|
||||
Apps = emqx_cth_suite:start(
|
||||
[
|
||||
emqx,
|
||||
emqx_conf,
|
||||
{emqx_license, #{
|
||||
config => #{license => #{key => emqx_license_test_lib:default_license()}}
|
||||
}}
|
||||
],
|
||||
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
||||
),
|
||||
[{suite_apps, Apps} | Config].
|
||||
|
||||
end_per_suite(_) ->
|
||||
emqx_common_test_helpers:stop_apps([emqx_license]),
|
||||
ok.
|
||||
|
||||
init_per_testcase(_Case, Config) ->
|
||||
{ok, _} = emqx_cluster_rpc:start_link(node(), emqx_cluster_rpc, 1000),
|
||||
Config.
|
||||
|
||||
end_per_testcase(_Case, _Config) ->
|
||||
ok.
|
||||
|
||||
set_special_configs(emqx_license) ->
|
||||
Config = #{key => emqx_license_test_lib:default_license()},
|
||||
emqx_config:put([license], Config);
|
||||
set_special_configs(_) ->
|
||||
ok.
|
||||
end_per_suite(Config) ->
|
||||
ok = emqx_cth_suite:stop(?config(suite_apps, Config)).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% Tests
|
||||
|
|
|
@ -15,26 +15,20 @@ all() ->
|
|||
emqx_common_test_helpers:all(?MODULE).
|
||||
|
||||
init_per_suite(Config) ->
|
||||
_ = application:load(emqx_conf),
|
||||
emqx_common_test_helpers:start_apps([emqx_license], fun set_special_configs/1),
|
||||
Config.
|
||||
Apps = emqx_cth_suite:start(
|
||||
[
|
||||
emqx,
|
||||
emqx_conf,
|
||||
{emqx_license, #{
|
||||
config => #{license => #{key => emqx_license_test_lib:default_license()}}
|
||||
}}
|
||||
],
|
||||
#{work_dir => emqx_cth_suite:work_dir(Config)}
|
||||
),
|
||||
[{suite_apps, Apps} | Config].
|
||||
|
||||
end_per_suite(_) ->
|
||||
emqx_common_test_helpers:stop_apps([emqx_license]),
|
||||
ok.
|
||||
|
||||
init_per_testcase(_Case, Config) ->
|
||||
{ok, _} = emqx_cluster_rpc:start_link(node(), emqx_cluster_rpc, 1000),
|
||||
Config.
|
||||
|
||||
end_per_testcase(_Case, _Config) ->
|
||||
ok.
|
||||
|
||||
set_special_configs(emqx_license) ->
|
||||
Config = #{key => emqx_license_test_lib:default_license()},
|
||||
emqx_config:put([license], Config);
|
||||
set_special_configs(_) ->
|
||||
ok.
|
||||
end_per_suite(Config) ->
|
||||
ok = emqx_cth_suite:stop(?config(suite_apps, Config)).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% Tests
|
||||
|
|
Loading…
Reference in New Issue