fix: validate error when set license's watermark to 100%

This commit is contained in:
zhongwencool 2023-11-28 13:10:31 +08:00
parent 95c96e2a3a
commit 29bcdb9a4a
2 changed files with 21 additions and 4 deletions

View File

@ -72,10 +72,16 @@ check_license_watermark(Conf) ->
undefined ->
true;
Low ->
High = hocon_maps:get("license.connection_high_watermark", Conf),
case High =/= undefined andalso High > Low of
true -> true;
false -> {bad_license_watermark, #{high => High, low => Low}}
case hocon_maps:get("license.connection_high_watermark", Conf) 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;
false -> {bad_license_watermark, #{high => High, low => Low}}
end
end
end.

View File

@ -194,6 +194,17 @@ t_license_setting(_Config) ->
?assertEqual(0.5, emqx_config:get([license, connection_low_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
?assertMatch(
{ok, 400, _},