mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Update pumactl to remove development as default environment (#2035)
* Update pumactl to remove development as default environment * Extract with_config_file test helper method * Extract config file base test class, use with_env for pumactl tests
This commit is contained in:
parent
a51206514c
commit
aa457c16d7
5 changed files with 89 additions and 42 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
* Bugfixes
|
* Bugfixes
|
||||||
* Fix Errno::EINVAL when SSL is enabled and browser rejects cert (#1564)
|
* Fix Errno::EINVAL when SSL is enabled and browser rejects cert (#1564)
|
||||||
|
* Fix pumactl defaulting puma to development if an environment was not specified (#2035)
|
||||||
|
|
||||||
## 4.2.1 / 2019-10-07
|
## 4.2.1 / 2019-10-07
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ module Puma
|
||||||
@control_auth_token = nil
|
@control_auth_token = nil
|
||||||
@config_file = nil
|
@config_file = nil
|
||||||
@command = nil
|
@command = nil
|
||||||
@environment = ENV['RACK_ENV'] || "development"
|
@environment = ENV['RACK_ENV']
|
||||||
|
|
||||||
@argv = argv.dup
|
@argv = argv.dup
|
||||||
@stdout = stdout
|
@stdout = stdout
|
||||||
|
@ -82,8 +82,10 @@ module Puma
|
||||||
@command = argv.shift
|
@command = argv.shift
|
||||||
|
|
||||||
unless @config_file == '-'
|
unless @config_file == '-'
|
||||||
|
environment = @environment || 'development'
|
||||||
|
|
||||||
if @config_file.nil?
|
if @config_file.nil?
|
||||||
@config_file = %W(config/puma/#{@environment}.rb config/puma.rb).find do |f|
|
@config_file = %W(config/puma/#{environment}.rb config/puma.rb).find do |f|
|
||||||
File.exist?(f)
|
File.exist?(f)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
16
test/helpers/config_file.rb
Normal file
16
test/helpers/config_file.rb
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
class TestConfigFileBase < Minitest::Test
|
||||||
|
private
|
||||||
|
|
||||||
|
def with_env(env = {})
|
||||||
|
original_env = {}
|
||||||
|
env.each do |k, v|
|
||||||
|
original_env[k] = ENV[k]
|
||||||
|
ENV[k] = v
|
||||||
|
end
|
||||||
|
yield
|
||||||
|
ensure
|
||||||
|
original_env.each do |k, v|
|
||||||
|
ENV[k] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,26 +1,10 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
require_relative "helpers/config_file"
|
||||||
|
|
||||||
require "puma/configuration"
|
require "puma/configuration"
|
||||||
|
|
||||||
class TestConfigFileBase < Minitest::Test
|
|
||||||
private
|
|
||||||
|
|
||||||
def with_env(env = {})
|
|
||||||
original_env = {}
|
|
||||||
env.each do |k, v|
|
|
||||||
original_env[k] = ENV[k]
|
|
||||||
ENV[k] = v
|
|
||||||
end
|
|
||||||
yield
|
|
||||||
ensure
|
|
||||||
original_env.each do |k, v|
|
|
||||||
ENV[k] = v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class TestConfigFile < TestConfigFileBase
|
class TestConfigFile < TestConfigFileBase
|
||||||
parallelize_me!
|
parallelize_me!
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
require_relative "helpers/config_file"
|
||||||
|
|
||||||
require 'puma/control_cli'
|
require 'puma/control_cli'
|
||||||
|
|
||||||
class TestPumaControlCli < Minitest::Test
|
class TestPumaControlCli < TestConfigFileBase
|
||||||
def setup
|
def setup
|
||||||
# use a pipe to get info across thread boundary
|
# use a pipe to get info across thread boundary
|
||||||
@wait, @ready = IO.pipe
|
@wait, @ready = IO.pipe
|
||||||
|
@ -24,38 +25,81 @@ class TestPumaControlCli < Minitest::Test
|
||||||
server.close
|
server.close
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def with_config_file(path_to_config, port)
|
||||||
|
path = Pathname.new(path_to_config)
|
||||||
|
Dir.mktmpdir do |tmp_dir|
|
||||||
|
Dir.chdir(tmp_dir) do
|
||||||
|
FileUtils.mkdir_p(path.dirname)
|
||||||
|
File.open(path, "w") { |f| f << "port #{port}" }
|
||||||
|
yield
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_config_file
|
def test_config_file
|
||||||
control_cli = Puma::ControlCLI.new ["--config-file", "test/config/state_file_testing_config.rb", "halt"]
|
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")
|
assert_equal "t3-pid", control_cli.instance_variable_get("@pidfile")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_environment
|
def test_rack_env_without_environment
|
||||||
ENV.delete 'RACK_ENV' # remove from travis
|
with_env("RACK_ENV" => "test") do
|
||||||
control_cli = Puma::ControlCLI.new ["halt"]
|
control_cli = Puma::ControlCLI.new ["halt"]
|
||||||
assert_equal "development", control_cli.instance_variable_get("@environment")
|
assert_equal "test", control_cli.instance_variable_get("@environment")
|
||||||
control_cli = Puma::ControlCLI.new ["-e", "test", "halt"]
|
end
|
||||||
assert_equal "test", control_cli.instance_variable_get("@environment")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_config_file_exist
|
def test_environment_without_rack_env
|
||||||
ENV.delete 'RACK_ENV' # remove from travis
|
with_env("RACK_ENV" => nil) do
|
||||||
port = 6001
|
control_cli = Puma::ControlCLI.new ["halt"]
|
||||||
Dir.mktmpdir do |d|
|
assert_nil control_cli.instance_variable_get("@environment")
|
||||||
Dir.chdir(d) do
|
|
||||||
FileUtils.mkdir("config")
|
control_cli = Puma::ControlCLI.new ["-e", "test", "halt"]
|
||||||
File.open("config/puma.rb", "w") { |f| f << "port #{port}" }
|
assert_equal "test", control_cli.instance_variable_get("@environment")
|
||||||
control_cli = Puma::ControlCLI.new ["halt"]
|
end
|
||||||
assert_equal "config/puma.rb",
|
end
|
||||||
control_cli.instance_variable_get("@config_file")
|
|
||||||
|
def test_environment_with_rack_env
|
||||||
|
with_env("RACK_ENV" => "production") do
|
||||||
|
control_cli = Puma::ControlCLI.new ["halt"]
|
||||||
|
assert_equal "production", control_cli.instance_variable_get("@environment")
|
||||||
|
|
||||||
|
control_cli = Puma::ControlCLI.new ["-e", "test", "halt"]
|
||||||
|
assert_equal "test", control_cli.instance_variable_get("@environment")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_environment_specific_config_file_exist
|
||||||
|
port = 6002
|
||||||
|
puma_config_file = "config/puma.rb"
|
||||||
|
production_config_file = "config/puma/production.rb"
|
||||||
|
|
||||||
|
with_env("RACK_ENV" => nil) do
|
||||||
|
with_config_file(puma_config_file, port) do
|
||||||
|
control_cli = Puma::ControlCLI.new ["-e", "production", "halt"]
|
||||||
|
assert_equal puma_config_file, control_cli.instance_variable_get("@config_file")
|
||||||
|
end
|
||||||
|
|
||||||
|
with_config_file(production_config_file, port) do
|
||||||
|
control_cli = Puma::ControlCLI.new ["-e", "production", "halt"]
|
||||||
|
assert_equal production_config_file, control_cli.instance_variable_get("@config_file")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Dir.mktmpdir do |d|
|
end
|
||||||
Dir.chdir(d) do
|
|
||||||
FileUtils.mkdir_p("config/puma")
|
def test_default_config_file_exist
|
||||||
File.open("config/puma/development.rb", "w") { |f| f << "port #{port}" }
|
port = 6001
|
||||||
|
puma_config_file = "config/puma.rb"
|
||||||
|
development_config_file = "config/puma/development.rb"
|
||||||
|
|
||||||
|
with_env("RACK_ENV" => nil) do
|
||||||
|
with_config_file(puma_config_file, port) do
|
||||||
control_cli = Puma::ControlCLI.new ["halt"]
|
control_cli = Puma::ControlCLI.new ["halt"]
|
||||||
assert_equal "config/puma/development.rb",
|
assert_equal puma_config_file, control_cli.instance_variable_get("@config_file")
|
||||||
control_cli.instance_variable_get("@config_file")
|
end
|
||||||
|
|
||||||
|
with_config_file(development_config_file, port) do
|
||||||
|
control_cli = Puma::ControlCLI.new ["halt"]
|
||||||
|
assert_equal development_config_file, control_cli.instance_variable_get("@config_file")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue