mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
da9243cdce
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@239 19e92222-5c0b-0410-8929-a290d50e31e9
101 lines
3.2 KiB
Ruby
101 lines
3.2 KiB
Ruby
# Mongrel Web Server - A Mostly Ruby Webserver and Library
|
|
#
|
|
# Copyright (C) 2005 Zed A. Shaw zedshaw AT zedshaw dot com
|
|
#
|
|
# This library is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
# License as published by the Free Software Foundation; either
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
#
|
|
# This library is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
# Lesser General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
# License along with this library; if not, write to the Free Software
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
require 'test/unit'
|
|
require 'mongrel'
|
|
require 'net/http'
|
|
require File.dirname(__FILE__) + "/testhelp.rb"
|
|
|
|
$test_plugin_fired = 0
|
|
|
|
class TestPlugin < GemPlugin::Plugin "/handlers"
|
|
include Mongrel::HttpHandlerPlugin
|
|
|
|
def process(request, response)
|
|
$test_plugin_fired += 1
|
|
end
|
|
end
|
|
|
|
|
|
class Sentinel < GemPlugin::Plugin "/handlers"
|
|
include Mongrel::HttpHandlerPlugin
|
|
|
|
def process(request, response)
|
|
raise "This Sentinel plugin shouldn't run."
|
|
end
|
|
end
|
|
|
|
|
|
class ConfiguratorTest < Test::Unit::TestCase
|
|
|
|
def test_base_handler_config
|
|
config = nil
|
|
|
|
redirect_test_io do
|
|
config = Mongrel::Configurator.new :host => "localhost" do
|
|
listener :port => 4501 do
|
|
# 2 in front should run, but the sentinel shouldn't since dirhandler processes the request
|
|
uri "/", :handler => plugin("/handlers/testplugin")
|
|
uri "/", :handler => plugin("/handlers/testplugin")
|
|
uri "/", :handler => Mongrel::DirHandler.new(".")
|
|
uri "/", :handler => plugin("/handlers/testplugin")
|
|
|
|
uri "/test", :handler => plugin("/handlers/testplugin")
|
|
uri "/test", :handler => plugin("/handlers/testplugin")
|
|
uri "/test", :handler => Mongrel::DirHandler.new(".")
|
|
uri "/test", :handler => plugin("/handlers/testplugin")
|
|
|
|
debug "/"
|
|
setup_signals
|
|
|
|
run_config(File.dirname(__FILE__) + "/../test/mongrel.conf")
|
|
load_mime_map(File.dirname(__FILE__) + "/../test/mime.yaml")
|
|
|
|
run
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
config.listeners.each do |host,listener|
|
|
assert listener.classifier.uris.length == 3, "Wrong number of registered URIs"
|
|
assert listener.classifier.uris.include?("/"), "/ not registered"
|
|
assert listener.classifier.uris.include?("/test"), "/test not registered"
|
|
end
|
|
|
|
res = Net::HTTP.get(URI.parse('http://localhost:4501/test'))
|
|
assert res != nil, "Didn't get a response"
|
|
assert $test_plugin_fired == 3, "Test filter plugin didn't run 3 times."
|
|
|
|
redirect_test_io do
|
|
res = Net::HTTP.get(URI.parse('http://localhost:4501/'))
|
|
|
|
assert res != nil, "Didn't get a response"
|
|
assert $test_plugin_fired == 6, "Test filter plugin didn't run 6 times."
|
|
end
|
|
|
|
redirect_test_io do
|
|
config.stop
|
|
end
|
|
|
|
assert_raise Errno::EBADF, Errno::ECONNREFUSED do
|
|
res = Net::HTTP.get(URI.parse("http://localhost:4501/"))
|
|
end
|
|
end
|
|
|
|
end
|