fix: validate error when set license's watermark to 100%
This commit is contained in:
parent
95c96e2a3a
commit
29bcdb9a4a
|
@ -72,11 +72,17 @@ check_license_watermark(Conf) ->
|
||||||
undefined ->
|
undefined ->
|
||||||
true;
|
true;
|
||||||
Low ->
|
Low ->
|
||||||
High = hocon_maps:get("license.connection_high_watermark", Conf),
|
case hocon_maps:get("license.connection_high_watermark", Conf) of
|
||||||
case High =/= undefined andalso High > Low of
|
undefined ->
|
||||||
|
{bad_license_watermark, #{high => undefined, low => Low}};
|
||||||
|
High ->
|
||||||
|
{ok, HighFloat} = emqx_schema:to_percent(High),
|
||||||
|
{ok, LowFloat} = emqx_schema:to_percent(Low),
|
||||||
|
case HighFloat > LowFloat of
|
||||||
true -> true;
|
true -> true;
|
||||||
false -> {bad_license_watermark, #{high => High, low => Low}}
|
false -> {bad_license_watermark, #{high => High, low => Low}}
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%% @doc The default license key.
|
%% @doc The default license key.
|
||||||
|
|
|
@ -194,6 +194,17 @@ t_license_setting(_Config) ->
|
||||||
?assertEqual(0.5, emqx_config:get([license, connection_low_watermark])),
|
?assertEqual(0.5, emqx_config:get([license, connection_low_watermark])),
|
||||||
?assertEqual(0.55, emqx_config:get([license, connection_high_watermark])),
|
?assertEqual(0.55, emqx_config:get([license, connection_high_watermark])),
|
||||||
|
|
||||||
|
%% update
|
||||||
|
Low1 = <<"50%">>,
|
||||||
|
High1 = <<"100%">>,
|
||||||
|
UpdateRes1 = request(put, uri(["license", "setting"]), #{
|
||||||
|
<<"connection_low_watermark">> => Low1,
|
||||||
|
<<"connection_high_watermark">> => High1
|
||||||
|
}),
|
||||||
|
validate_setting(UpdateRes1, Low1, High1),
|
||||||
|
?assertEqual(0.5, emqx_config:get([license, connection_low_watermark])),
|
||||||
|
?assertEqual(1.0, emqx_config:get([license, connection_high_watermark])),
|
||||||
|
|
||||||
%% update bad setting low >= high
|
%% update bad setting low >= high
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
{ok, 400, _},
|
{ok, 400, _},
|
||||||
|
|
Loading…
Reference in New Issue