Detailed error message in memory threshold validation
This commit is contained in:
parent
6e5dddc0fc
commit
7b689ae633
|
|
@ -40,7 +40,12 @@ defmodule RabbitMQ.CLI.Ctl.Commands.SetVmMemoryHighWatermarkCommand do
|
|||
{_, rest} ->
|
||||
case Enum.member?(Helpers.memory_units, rest) do
|
||||
true -> :ok
|
||||
false -> {:validation_failure, :bad_argument}
|
||||
false -> case Float.parse(arg) do
|
||||
{_, orest} when orest == rest ->
|
||||
{:validation_failure, {:bad_argument, "Invalid units."}}
|
||||
_ ->
|
||||
{:validation_failure, {:bad_argument, "The threshold should be an integer."}}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -50,12 +55,12 @@ defmodule RabbitMQ.CLI.Ctl.Commands.SetVmMemoryHighWatermarkCommand do
|
|||
end
|
||||
|
||||
def validate([arg], _) when is_number(arg) and (arg < 0.0 or arg > 1.0) do
|
||||
{:validation_failure, :bad_argument}
|
||||
{:validation_failure, {:bad_argument, "The threshold should be a fraction between 0.0 and 1.0"}}
|
||||
end
|
||||
def validate([arg], %{}) when is_binary(arg) do
|
||||
case Float.parse(arg) do
|
||||
{arg, ""} when is_number(arg) and (arg < 0.0 or arg > 1.0) ->
|
||||
{:validation_failure, :bad_argument}
|
||||
{:validation_failure, {:bad_argument, "The threshold should be a fraction between 0.0 and 1.0"}}
|
||||
{_, ""} -> :ok
|
||||
_ -> {:validation_failure, :bad_argument}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -65,11 +65,15 @@ defmodule SetVmMemoryHighWatermarkCommandTest do
|
|||
end
|
||||
|
||||
test "validate: a negative number returns a bad argument", context do
|
||||
assert @command.validate(["-0.1"], context[:opts]) == {:validation_failure, :bad_argument}
|
||||
assert @command.validate(["-0.1"], context[:opts]) == {:validation_failure, {:bad_argument, "The threshold should be a fraction between 0.0 and 1.0"}}
|
||||
end
|
||||
|
||||
test "validate: a percentage returns a bad argument", context do
|
||||
assert @command.validate(["40"], context[:opts]) == {:validation_failure, {:bad_argument, "The threshold should be a fraction between 0.0 and 1.0"}}
|
||||
end
|
||||
|
||||
test "validate: a value greater than 1.0 returns a bad argument", context do
|
||||
assert @command.validate(["1.1"], context[:opts]) == {:validation_failure, :bad_argument}
|
||||
assert @command.validate(["1.1"], context[:opts]) == {:validation_failure, {:bad_argument, "The threshold should be a fraction between 0.0 and 1.0"}}
|
||||
end
|
||||
|
||||
test "run: on an invalid node, return a bad rpc" do
|
||||
|
|
@ -100,7 +104,15 @@ defmodule SetVmMemoryHighWatermarkCommandTest do
|
|||
end
|
||||
|
||||
test "validate: a single absolute integer with an invalid memory unit fails ", context do
|
||||
assert @command.validate(["absolute","10bytes"], context[:opts]) == {:validation_failure, :bad_argument}
|
||||
assert @command.validate(["absolute","10bytes"], context[:opts]) == {:validation_failure, {:bad_argument, "Invalid units."}}
|
||||
end
|
||||
|
||||
test "validate: a single absolute float with a valid memory unit fails ", context do
|
||||
assert @command.validate(["absolute","10.0MB"], context[:opts]) == {:validation_failure, {:bad_argument, "The threshold should be an integer."}}
|
||||
end
|
||||
|
||||
test "validate: a single absolute float with an invalid memory unit fails ", context do
|
||||
assert @command.validate(["absolute","10.0bytes"], context[:opts]) == {:validation_failure, {:bad_argument, "The threshold should be an integer."}}
|
||||
end
|
||||
|
||||
test "validate: a single absolute string fails ", context do
|
||||
|
|
|
|||
Loading…
Reference in New Issue