test: ensure coverage for the `no_license` case
This commit is contained in:
parent
c936706a1f
commit
ae9c8098ba
|
@ -15,6 +15,7 @@
|
|||
start_link/2,
|
||||
update/1,
|
||||
dump/0,
|
||||
purge/0,
|
||||
limits/0]).
|
||||
|
||||
%% gen_server callbacks
|
||||
|
@ -23,6 +24,8 @@
|
|||
handle_cast/2,
|
||||
handle_info/2]).
|
||||
|
||||
-define(LICENSE_TAB, emqx_license).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% API
|
||||
%%------------------------------------------------------------------------------
|
||||
|
@ -39,15 +42,15 @@ start_link(LicenseFetcher, CheckInterval) ->
|
|||
|
||||
-spec update(emqx_license_parser:license()) -> ok.
|
||||
update(License) ->
|
||||
gen_server:call(?MODULE, {update, License}).
|
||||
gen_server:call(?MODULE, {update, License}, infinity).
|
||||
|
||||
-spec dump() -> [{atom(), term()}].
|
||||
dump() ->
|
||||
gen_server:call(?MODULE, dump).
|
||||
gen_server:call(?MODULE, dump, infinity).
|
||||
|
||||
-spec limits() -> {ok, limits()} | {error, any()}.
|
||||
limits() ->
|
||||
try ets:lookup(?MODULE, limits) of
|
||||
try ets:lookup(?LICENSE_TAB, limits) of
|
||||
[{limits, Limits}] -> {ok, Limits};
|
||||
_ -> {error, no_license}
|
||||
catch
|
||||
|
@ -55,6 +58,11 @@ limits() ->
|
|||
{error, no_license}
|
||||
end.
|
||||
|
||||
%% @doc Force purge the license table.
|
||||
-spec purge() -> ok.
|
||||
purge() ->
|
||||
gen_server:call(?MODULE, purge, infinity).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% gen_server callbacks
|
||||
%%------------------------------------------------------------------------------
|
||||
|
@ -62,7 +70,7 @@ limits() ->
|
|||
init([LicenseFetcher, CheckInterval]) ->
|
||||
case LicenseFetcher() of
|
||||
{ok, License} ->
|
||||
_ = ets:new(?MODULE, [set, protected, named_table]),
|
||||
?LICENSE_TAB = ets:new(?LICENSE_TAB, [set, protected, named_table]),
|
||||
#{} = check_license(License),
|
||||
State = ensure_timer(#{check_license_interval => CheckInterval,
|
||||
license => License}),
|
||||
|
@ -73,10 +81,11 @@ init([LicenseFetcher, CheckInterval]) ->
|
|||
|
||||
handle_call({update, License}, _From, State) ->
|
||||
{reply, check_license(License), State#{license => License}};
|
||||
|
||||
handle_call(dump, _From, #{license := License} = State) ->
|
||||
{reply, emqx_license_parser:dump(License), State};
|
||||
|
||||
handle_call(purge, _From, State) ->
|
||||
_ = ets:delete_all_objects(?LICENSE_TAB),
|
||||
{reply, ok, State};
|
||||
handle_call(_Req, _From, State) ->
|
||||
{reply, unknown, State}.
|
||||
|
||||
|
@ -137,4 +146,4 @@ small_customer_overexpired(?SMALL_CUSTOMER, DaysLeft)
|
|||
small_customer_overexpired(_CType, _DaysLeft) -> false.
|
||||
|
||||
apply_limits(Limits) ->
|
||||
ets:insert(?MODULE, {limits, Limits}).
|
||||
ets:insert(?LICENSE_TAB, {limits, Limits}).
|
||||
|
|
|
@ -153,6 +153,12 @@ t_check_expired(_Config) ->
|
|||
{stop, {error, ?RC_QUOTA_EXCEEDED}},
|
||||
emqx_license:check(#{}, #{})).
|
||||
|
||||
t_check_not_loaded(_Config) ->
|
||||
ok = emqx_license_checker:purge(),
|
||||
?assertEqual(
|
||||
{stop, {error, ?RC_QUOTA_EXCEEDED}},
|
||||
emqx_license:check(#{}, #{})).
|
||||
|
||||
%%------------------------------------------------------------------------------
|
||||
%% Helpers
|
||||
%%------------------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue