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