83 lines
2.5 KiB
Erlang
83 lines
2.5 KiB
Erlang
%%--------------------------------------------------------------------
|
|
%% Copyright (c) 2022-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
|
|
%%--------------------------------------------------------------------
|
|
|
|
-module(emqx_license_cli_SUITE).
|
|
|
|
-compile(nowarn_export_all).
|
|
-compile(export_all).
|
|
|
|
-include_lib("eunit/include/eunit.hrl").
|
|
-include_lib("common_test/include/ct.hrl").
|
|
|
|
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.
|
|
|
|
end_per_suite(_) ->
|
|
emqx_common_test_helpers:stop_apps([emqx_license]),
|
|
ok.
|
|
|
|
init_per_testcase(_Case, Config) ->
|
|
ok = persistent_term:put(
|
|
emqx_license_test_pubkey,
|
|
emqx_license_test_lib:public_key_pem()
|
|
),
|
|
{ok, _} = emqx_cluster_rpc:start_link(node(), emqx_cluster_rpc, 1000),
|
|
Config.
|
|
|
|
end_per_testcase(_Case, _Config) ->
|
|
persistent_term:erase(emqx_license_test_pubkey),
|
|
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
|
|
%%------------------------------------------------------------------------------
|
|
|
|
t_help(_Config) ->
|
|
_ = emqx_license_cli:license([]).
|
|
|
|
t_info(_Config) ->
|
|
_ = emqx_license_cli:license(["info"]).
|
|
|
|
t_update(_Config) ->
|
|
LicenseValue = emqx_license_test_lib:default_license(),
|
|
_ = emqx_license_cli:license(["update", LicenseValue]),
|
|
_ = emqx_license_cli:license(["reload"]),
|
|
_ = emqx_license_cli:license(["update", "Invalid License Value"]).
|
|
|
|
t_conf_update(_Config) ->
|
|
LicenseKey = emqx_license_test_lib:make_license(#{max_connections => "123"}),
|
|
Conf = #{
|
|
<<"connection_high_watermark">> => <<"50%">>,
|
|
<<"connection_low_watermark">> => <<"45%">>,
|
|
<<"key">> => LicenseKey
|
|
},
|
|
?assertMatch({ok, _}, emqx:update_config([license], Conf)),
|
|
?assertEqual(
|
|
#{
|
|
connection_high_watermark => 0.5,
|
|
connection_low_watermark => 0.45,
|
|
key => LicenseKey
|
|
},
|
|
emqx:get_config([license])
|
|
),
|
|
?assertMatch(
|
|
#{max_connections := 123},
|
|
maps:from_list(emqx_license_checker:dump())
|
|
),
|
|
ok.
|