2016-11-22 10:05:49 -05:00
|
|
|
require "test_helper"
|
2011-12-07 16:42:53 -05:00
|
|
|
|
2016-11-22 10:05:49 -05:00
|
|
|
require "puma/configuration"
|
2011-12-07 16:42:53 -05:00
|
|
|
|
2016-11-22 10:05:49 -05:00
|
|
|
class TestConfigFile < Minitest::Test
|
2015-04-29 14:51:25 -04:00
|
|
|
def test_app_from_rackup
|
2016-02-06 22:00:29 -05:00
|
|
|
conf = Puma::Configuration.new do |c|
|
|
|
|
c.rackup "test/hello-bind.ru"
|
|
|
|
end
|
2015-04-29 14:51:25 -04:00
|
|
|
conf.load
|
|
|
|
|
|
|
|
conf.app
|
|
|
|
|
|
|
|
assert_equal ["tcp://127.0.0.1:9292"], conf.options[:binds]
|
|
|
|
end
|
|
|
|
|
2011-12-07 16:42:53 -05:00
|
|
|
def test_app_from_app_DSL
|
2016-02-06 22:00:29 -05:00
|
|
|
conf = Puma::Configuration.new do |c|
|
|
|
|
c.load "test/config/app.rb"
|
|
|
|
end
|
2011-12-07 16:42:53 -05:00
|
|
|
conf.load
|
|
|
|
|
|
|
|
app = conf.app
|
|
|
|
|
2013-02-06 17:44:51 -05:00
|
|
|
assert_equal [200, {}, ["embedded app"]], app.call({})
|
2011-12-07 16:42:53 -05:00
|
|
|
end
|
2014-02-17 12:07:17 -05:00
|
|
|
|
2015-02-16 18:44:43 -05:00
|
|
|
def test_double_bind_port
|
2015-07-29 10:16:24 -04:00
|
|
|
port = (rand(10_000) + 30_000).to_s
|
2015-02-16 18:44:43 -05:00
|
|
|
with_env("PORT" => port) do
|
2017-03-03 16:11:59 -05:00
|
|
|
conf = Puma::Configuration.new do |user_config, file_config, default_config|
|
|
|
|
user_config.bind "tcp://#{Puma::Configuration::DefaultTCPHost}:#{port}"
|
|
|
|
file_config.load "test/config/app.rb"
|
2016-02-06 22:00:29 -05:00
|
|
|
end
|
|
|
|
|
2015-02-16 18:44:43 -05:00
|
|
|
conf.load
|
|
|
|
assert_equal ["tcp://0.0.0.0:#{port}"], conf.options[:binds]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-17 12:07:17 -05:00
|
|
|
def test_lowleve_error_handler_DSL
|
2016-02-06 22:00:29 -05:00
|
|
|
conf = Puma::Configuration.new do |c|
|
|
|
|
c.load "test/config/app.rb"
|
|
|
|
end
|
2014-02-17 12:07:17 -05:00
|
|
|
conf.load
|
|
|
|
|
|
|
|
app = conf.options[:lowlevel_error_handler]
|
|
|
|
|
|
|
|
assert_equal [200, {}, ["error page"]], app.call({})
|
|
|
|
end
|
2015-02-16 18:44:43 -05:00
|
|
|
|
2016-03-26 10:48:36 -04:00
|
|
|
def test_allow_users_to_override_default_options
|
|
|
|
conf = Puma::Configuration.new(restart_cmd: 'bin/rails server')
|
|
|
|
|
|
|
|
assert_equal 'bin/rails server', conf.options[:restart_cmd]
|
|
|
|
end
|
|
|
|
|
2016-11-20 14:10:34 -05:00
|
|
|
def test_overwrite_options
|
|
|
|
conf = Puma::Configuration.new do |c|
|
|
|
|
c.workers 3
|
|
|
|
end
|
|
|
|
conf.load
|
|
|
|
|
|
|
|
assert_equal conf.options[:workers], 3
|
|
|
|
conf.options[:workers] += 1
|
|
|
|
assert_equal conf.options[:workers], 4
|
|
|
|
end
|
|
|
|
|
2017-03-06 13:28:44 -05:00
|
|
|
def test_explicit_config_files
|
|
|
|
conf = Puma::Configuration.new(config_files: ['test/config/settings.rb']) do |c|
|
|
|
|
end
|
|
|
|
conf.load
|
|
|
|
assert_match(/:3000$/, conf.options[:binds].first)
|
|
|
|
end
|
|
|
|
|
2017-01-30 23:29:19 -05:00
|
|
|
def test_parameters_overwrite_files
|
|
|
|
conf = Puma::Configuration.new(config_files: ['test/config/settings.rb']) do |c|
|
|
|
|
c.port 3030
|
|
|
|
end
|
|
|
|
conf.load
|
|
|
|
|
|
|
|
assert_match(/:3030$/, conf.options[:binds].first)
|
|
|
|
assert_equal 3, conf.options[:min_threads]
|
|
|
|
assert_equal 5, conf.options[:max_threads]
|
|
|
|
end
|
|
|
|
|
2015-02-16 18:44:43 -05:00
|
|
|
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
|
2011-12-07 16:42:53 -05:00
|
|
|
end
|