1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Add tests for ControlCLI when command is invalid/not present (#2248)

This change adds tests
for the scenario where the
ControlCLI exits with an EXIT_FAILURE when:

1. No command is issued to the ControlCLI
2. An invalid command is issued to the ControlCLI
This commit is contained in:
Manoj M J 2020-05-06 12:45:05 +05:30 committed by GitHub
parent 774c460e60
commit b9b406028c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 10 deletions

View file

@ -82,6 +82,15 @@ module Puma
@command = argv.shift
# check presence of command
unless @command
raise "Available commands: #{COMMANDS.join(", ")}"
end
unless COMMANDS.include? @command
raise "Invalid command: #{@command}"
end
unless @config_file == '-'
environment = @environment || 'development'
@ -100,16 +109,6 @@ module Puma
@pidfile ||= config.options[:pidfile]
end
end
# check present of command
unless @command
raise "Available commands: #{COMMANDS.join(", ")}"
end
unless COMMANDS.include? @command
raise "Invalid command: #{@command}"
end
rescue => e
@stdout.puts e.message
exit 1

View file

@ -33,6 +33,14 @@ class TestPumaControlCli < TestConfigFileBase
end
end
def test_blank_command
assert_system_exit_with_cli_output [], "Available commands: #{Puma::ControlCLI::COMMANDS.join(", ")}"
end
def test_invalid_command
assert_system_exit_with_cli_output ['an-invalid-command'], 'Invalid command: an-invalid-command'
end
def test_config_file
control_cli = Puma::ControlCLI.new ["--config-file", "test/config/state_file_testing_config.rb", "halt"]
assert_equal "t3-pid", control_cli.instance_variable_get("@pidfile")
@ -175,4 +183,16 @@ class TestPumaControlCli < TestConfigFileBase
end
assert_match expected_out, out
end
def assert_system_exit_with_cli_output(options, expected_out)
out, _ = capture_subprocess_io do
response = assert_raises(SystemExit) do
Puma::ControlCLI.new(options).run
end
assert_equal(response.status, 1)
end
assert_match expected_out, out
end
end