emqx/lib-ee/emqx_license/test/emqx_license_resources_SUIT...

90 lines
2.6 KiB
Erlang

%%--------------------------------------------------------------------
%% Copyright (c) 2022-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
%%--------------------------------------------------------------------
-module(emqx_license_resources_SUITE).
-compile(nowarn_export_all).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl").
-include_lib("snabbkaffe/include/snabbkaffe.hrl").
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.
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.
%%------------------------------------------------------------------------------
%% Tests
%%------------------------------------------------------------------------------
t_connection_count(_Config) ->
?check_trace(
begin
?wait_async_action(
whereis(emqx_license_resources) ! update_resources,
#{?snk_kind := emqx_license_resources_updated},
1000
),
emqx_license_resources:connection_count()
end,
fun(ConnCount, Trace) ->
?assertEqual(0, ConnCount),
?assertMatch([_ | _], ?of_kind(emqx_license_resources_updated, Trace))
end
),
meck:new(emqx_cm, [passthrough]),
meck:expect(emqx_cm, get_connected_client_count, fun() -> 10 end),
meck:new(emqx_license_proto_v2, [passthrough]),
meck:expect(
emqx_license_proto_v2,
remote_connection_counts,
fun(_Nodes) ->
[{ok, 5}, {error, some_error}]
end
),
?check_trace(
begin
?wait_async_action(
whereis(emqx_license_resources) ! update_resources,
#{?snk_kind := emqx_license_resources_updated},
1000
),
emqx_license_resources:connection_count()
end,
fun(ConnCount, _Trace) ->
?assertEqual(15, ConnCount)
end
),
meck:unload(emqx_license_proto_v2),
meck:unload(emqx_cm).
t_emqx_license_proto(_Config) ->
?assert("5.0.0" =< emqx_license_proto_v2:introduced_in()).