fix: validate error when set license's watermark to 100%
This commit is contained in:
parent
95c96e2a3a
commit
29bcdb9a4a
|
@ -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.
|
||||
|
||||
|
|
|
@ -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, _},
|
||||
|
|
Loading…
Reference in New Issue