From f6c63f950d033e28567fabfc47a57f938c4cbabf Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 4 Nov 2009 15:38:59 -0800 Subject: tests for RACK_ENV preservation Prevent ourselves from breaking things in case applications start depending on this. --- test/exec/test_exec.rb | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/test/exec/test_exec.rb b/test/exec/test_exec.rb index 4625b45..28ba24c 100644 --- a/test/exec/test_exec.rb +++ b/test/exec/test_exec.rb @@ -28,6 +28,13 @@ use Rack::ContentLength run proc { |env| [ 200, { 'Content-Type' => 'text/plain' }, [ "HI\\n" ] ] } EOS + SHOW_RACK_ENV = <<-EOS +use Rack::ContentLength +run proc { |env| + [ 200, { 'Content-Type' => 'text/plain' }, [ ENV['RACK_ENV'] ] ] +} + EOS + HELLO = <<-EOS class Hello def call(env) @@ -186,6 +193,46 @@ EOF assert_shutdown(pid) end + def test_rack_env_unset + File.open("config.ru", "wb") { |fp| fp.syswrite(SHOW_RACK_ENV) } + pid = fork { redirect_test_io { exec($unicorn_bin, "-l#@addr:#@port") } } + results = retry_hit(["http://#{@addr}:#{@port}/"]) + assert_equal "development", results.first + assert_shutdown(pid) + end + + def test_rack_env_cli_set + File.open("config.ru", "wb") { |fp| fp.syswrite(SHOW_RACK_ENV) } + pid = fork { + redirect_test_io { exec($unicorn_bin, "-l#@addr:#@port", "-Easdf") } + } + results = retry_hit(["http://#{@addr}:#{@port}/"]) + assert_equal "asdf", results.first + assert_shutdown(pid) + end + + def test_rack_env_ENV_set + File.open("config.ru", "wb") { |fp| fp.syswrite(SHOW_RACK_ENV) } + pid = fork { + ENV["RACK_ENV"] = "foobar" + redirect_test_io { exec($unicorn_bin, "-l#@addr:#@port") } + } + results = retry_hit(["http://#{@addr}:#{@port}/"]) + assert_equal "foobar", results.first + assert_shutdown(pid) + end + + def test_rack_env_cli_override_ENV + File.open("config.ru", "wb") { |fp| fp.syswrite(SHOW_RACK_ENV) } + pid = fork { + ENV["RACK_ENV"] = "foobar" + redirect_test_io { exec($unicorn_bin, "-l#@addr:#@port", "-Easdf") } + } + results = retry_hit(["http://#{@addr}:#{@port}/"]) + assert_equal "asdf", results.first + assert_shutdown(pid) + end + def test_ttin_ttou File.open("config.ru", "wb") { |fp| fp.syswrite(HI) } pid = fork { redirect_test_io { exec($unicorn_bin, "-l#@addr:#@port") } } -- cgit v1.2.3-24-ge0c7