2020-07-12 02:23:07 +08:00
|
|
|
## This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
## License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
## file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
2016-03-05 01:42:43 +08:00
|
|
|
##
|
2020-03-10 22:39:56 +08:00
|
|
|
## Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.
|
2016-03-05 01:42:43 +08:00
|
|
|
|
|
|
|
|
|
|
|
defmodule HelpCommandTest do
|
|
|
|
use ExUnit.Case, async: false
|
2017-03-09 23:11:31 +08:00
|
|
|
import TestHelper
|
2016-03-05 01:42:43 +08:00
|
|
|
|
2020-06-29 08:57:52 +08:00
|
|
|
alias RabbitMQ.CLI.Core.{CommandModules}
|
2016-06-09 08:34:56 +08:00
|
|
|
|
2016-06-10 07:54:22 +08:00
|
|
|
@command RabbitMQ.CLI.Ctl.Commands.HelpCommand
|
2016-06-02 08:24:15 +08:00
|
|
|
|
2016-03-05 01:42:43 +08:00
|
|
|
setup_all do
|
2017-03-09 23:11:31 +08:00
|
|
|
set_scope(:all)
|
2016-03-05 01:42:43 +08:00
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
2020-06-29 08:57:52 +08:00
|
|
|
test "validate: providing no position arguments passes validation" do
|
|
|
|
assert @command.validate([], %{}) == :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
test "validate: providing one position argument passes validation" do
|
|
|
|
assert @command.validate(["status"], %{}) == :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
test "validate: providing two or more position arguments fails validation" do
|
|
|
|
assert @command.validate(["extra1", "extra2"], %{}) ==
|
|
|
|
{:validation_failure, :too_many_args}
|
|
|
|
end
|
|
|
|
|
2017-02-07 20:43:24 +08:00
|
|
|
test "run: prints basic usage info" do
|
2020-06-29 08:57:52 +08:00
|
|
|
{:ok, lines} = @command.run([], %{})
|
|
|
|
output = Enum.join(lines, "\n")
|
2019-02-21 21:35:21 +08:00
|
|
|
assert output =~ ~r/[-n <node>] [-t <timeout>]/
|
2019-03-17 18:54:18 +08:00
|
|
|
assert output =~ ~r/commands/i
|
2016-05-26 07:04:24 +08:00
|
|
|
end
|
|
|
|
|
2019-01-22 13:53:50 +08:00
|
|
|
test "run: ctl command usage info is printed if command is specified" do
|
|
|
|
ctl_commands = CommandModules.module_map
|
|
|
|
|> Enum.filter(fn({_name, command_mod}) ->
|
|
|
|
to_string(command_mod) =~ ~r/^RabbitMQ\.CLI\.Ctl\.Commands/
|
|
|
|
end)
|
|
|
|
|> Enum.map(fn({name, _}) -> name end)
|
|
|
|
|
|
|
|
IO.inspect(ctl_commands)
|
|
|
|
Enum.each(
|
|
|
|
ctl_commands,
|
|
|
|
fn(command) ->
|
|
|
|
assert @command.run([command], %{}) =~ ~r/#{command}/
|
|
|
|
end)
|
2016-03-05 01:42:43 +08:00
|
|
|
end
|
|
|
|
|
2017-02-07 20:43:24 +08:00
|
|
|
test "run prints command info" do
|
2019-01-22 13:53:50 +08:00
|
|
|
ctl_commands = CommandModules.module_map
|
|
|
|
|> Enum.filter(fn({_name, command_mod}) ->
|
|
|
|
to_string(command_mod) =~ ~r/^RabbitMQ\.CLI\.Ctl\.Commands/
|
|
|
|
end)
|
|
|
|
|> Enum.map(fn({name, _}) -> name end)
|
|
|
|
|
|
|
|
Enum.each(
|
|
|
|
ctl_commands,
|
|
|
|
fn(command) ->
|
2020-06-29 08:57:52 +08:00
|
|
|
{:ok, lines} = @command.run([], %{})
|
|
|
|
output = Enum.join(lines, "\n")
|
|
|
|
assert output =~ ~r/\n\s+#{command}.*\n/
|
2019-01-22 13:53:50 +08:00
|
|
|
end)
|
2016-03-05 06:36:49 +08:00
|
|
|
end
|
|
|
|
|
2020-06-29 08:57:52 +08:00
|
|
|
test "run: exits with the code of OK" do
|
|
|
|
assert @command.output({:ok, "Help string"}, %{}) ==
|
|
|
|
{:ok, "Help string"}
|
2016-08-22 19:58:37 +08:00
|
|
|
end
|
2016-03-05 01:42:43 +08:00
|
|
|
end
|