summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2012-11-15 16:16:36 -0800
committerBryan McLellan <btm@opscode.com>2012-11-27 12:04:18 -0800
commit40eb061dac38dad114054b77e235c84b3606cfef (patch)
tree5f5b67406a0df7b34ea6ab87de0e7cd0e0e1adaa
parente54c79b68bb5e9c768675cc0094ea4f83a8da06f (diff)
downloadchef-40eb061dac38dad114054b77e235c84b3606cfef.tar.gz
replace thin w/ webrick for func. test server
-rw-r--r--chef/Gemfile6
-rw-r--r--chef/spec/functional/knife/cookbook_delete_spec.rb2
-rw-r--r--chef/spec/functional/knife/exec_spec.rb6
-rw-r--r--chef/spec/functional/knife/ssh_spec.rb1
-rw-r--r--chef/spec/functional/resource/remote_file_spec.rb1
-rw-r--r--chef/spec/functional/tiny_server_spec.rb9
-rw-r--r--chef/spec/tiny_server.rb39
7 files changed, 36 insertions, 28 deletions
diff --git a/chef/Gemfile b/chef/Gemfile
index 858484d83c..b912e8d7b9 100644
--- a/chef/Gemfile
+++ b/chef/Gemfile
@@ -8,12 +8,6 @@ gem "ronn"
group(:development, :test) do
gem 'rack'
- gem 'thin'
-
- # Eventmachine 1.0.0 is causing functional test failures on Solaris
- # 9 SPARC. Pinning em to 0.12.10 solves this issue until we can
- # replace thin with webrat or some other alternative.
- gem 'eventmachine', '0.12.10', :platforms => :ruby
gem 'ruby-shadow', :platforms => :ruby unless RUBY_PLATFORM.downcase.match(/(darwin|freebsd)/)
# gem 'awesome_print'
diff --git a/chef/spec/functional/knife/cookbook_delete_spec.rb b/chef/spec/functional/knife/cookbook_delete_spec.rb
index 54081263f0..ef38cb2e1f 100644
--- a/chef/spec/functional/knife/cookbook_delete_spec.rb
+++ b/chef/spec/functional/knife/cookbook_delete_spec.rb
@@ -23,8 +23,6 @@ describe Chef::Knife::CookbookDelete do
before(:all) do
@original_config = Chef::Config.hash_dup
- Thin::Logging.silent = true
-
@server = TinyServer::Manager.new
@server.start
end
diff --git a/chef/spec/functional/knife/exec_spec.rb b/chef/spec/functional/knife/exec_spec.rb
index ab3f38ac94..22162e02a2 100644
--- a/chef/spec/functional/knife/exec_spec.rb
+++ b/chef/spec/functional/knife/exec_spec.rb
@@ -6,9 +6,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,8 +23,6 @@ describe Chef::Knife::Exec do
before(:all) do
@original_config = Chef::Config.hash_dup
- Thin::Logging.silent = false
-
@server = TinyServer::Manager.new#(:debug => true)
@server.start
end
diff --git a/chef/spec/functional/knife/ssh_spec.rb b/chef/spec/functional/knife/ssh_spec.rb
index 8f87e53bf7..696fd58c4d 100644
--- a/chef/spec/functional/knife/ssh_spec.rb
+++ b/chef/spec/functional/knife/ssh_spec.rb
@@ -24,7 +24,6 @@ describe Chef::Knife::Ssh do
before(:all) do
@original_config = Chef::Config.hash_dup
Chef::Knife::Ssh.load_deps
- Thin::Logging.silent = true
@server = TinyServer::Manager.new
@server.start
end
diff --git a/chef/spec/functional/resource/remote_file_spec.rb b/chef/spec/functional/resource/remote_file_spec.rb
index e695e8feae..2ebeecd3d1 100644
--- a/chef/spec/functional/resource/remote_file_spec.rb
+++ b/chef/spec/functional/resource/remote_file_spec.rb
@@ -40,7 +40,6 @@ describe Chef::Resource::RemoteFile do
end
before(:all) do
- Thin::Logging.silent = false
@server = TinyServer::Manager.new
@server.start
@api = TinyServer::API.instance
diff --git a/chef/spec/functional/tiny_server_spec.rb b/chef/spec/functional/tiny_server_spec.rb
index 0cfef4305f..68ab9e7294 100644
--- a/chef/spec/functional/tiny_server_spec.rb
+++ b/chef/spec/functional/tiny_server_spec.rb
@@ -37,15 +37,16 @@ describe TinyServer::API do
it "creates a route for a GET request" do
@api.get('/foo/bar', 200, 'hello foobar')
- response = @api.call("REQUEST_METHOD" => "GET", "REQUEST_URI" => '/foo/bar')
- response.should == [200, {'Content-Type' => 'application/json'}, 'hello foobar']
+ # WEBrick gives you the full URI with host, Thin only gave the part after scheme+host+port
+ response = @api.call("REQUEST_METHOD" => "GET", "REQUEST_URI" => 'http://localhost:1974/foo/bar')
+ response.should == [200, {'Content-Type' => 'application/json'}, [ 'hello foobar' ]]
end
it "creates a route for a request with a block" do
block_called = false
@api.get('/bar/baz', 200) { block_called = true; 'hello barbaz' }
- response = @api.call("REQUEST_METHOD" => "GET", "REQUEST_URI" => '/bar/baz')
- response.should == [200, {'Content-Type' => 'application/json'}, 'hello barbaz']
+ response = @api.call("REQUEST_METHOD" => "GET", "REQUEST_URI" => 'http://localhost:1974/bar/baz')
+ response.should == [200, {'Content-Type' => 'application/json'}, [ 'hello barbaz' ]]
block_called.should be_true
end
diff --git a/chef/spec/tiny_server.rb b/chef/spec/tiny_server.rb
index ae8518097b..ba75cd57c1 100644
--- a/chef/spec/tiny_server.rb
+++ b/chef/spec/tiny_server.rb
@@ -17,11 +17,13 @@
#
require 'rubygems'
+require 'webrick'
require 'rack'
-require 'thin'
+#require 'thin'
require 'singleton'
require 'chef/json_compat'
require 'open-uri'
+require 'chef/config'
module TinyServer
@@ -29,30 +31,42 @@ module TinyServer
attr_writer :app
- def self.run(options=nil, &block)
+ def self.setup(options=nil, &block)
tiny_app = new(options)
app_code = Rack::Builder.new(&block).to_app
tiny_app.app = app_code
- tiny_app.start
+ tiny_app
+ end
+
+ def shutdown
+ server.shutdown
end
end
class Manager
- DEFAULT_OPTIONS = {:server => 'thin', :Port => 9000, :Host => 'localhost', :environment => :none}
+ # 5 == debug, 3 == warning
+ LOGGER = WEBrick::Log.new(STDOUT, 3)
+ DEFAULT_OPTIONS = {
+ :server => 'webrick',
+ :Port => 9000,
+ :Host => 'localhost',
+ :environment => :none,
+ :Logger => LOGGER,
+ :AccessLog => [] # Remove this option to enable the access log when debugging.
+ }
def initialize(options=nil)
@options = options ? DEFAULT_OPTIONS.merge(options) : DEFAULT_OPTIONS
@creator = caller.first
-
- Thin::Logging.silent = !@options[:debug]
end
def start
@server_thread = Thread.new do
- @server = Server.run(@options) do
+ @server = Server.setup(@options) do
run API.instance
end
+ @server.start
end
block_until_started
end
@@ -63,7 +77,10 @@ module TinyServer
def block_until_started
200.times do
- return true if started?
+ if started?
+ raise "ivar weirdness" if @server.nil?
+ return true
+ end
end
raise "TinyServer failed to boot :/"
end
@@ -84,6 +101,7 @@ module TinyServer
def stop
# yes, this is terrible.
+ @server.shutdown
@server_thread.kill
@server_thread.join
@server_thread = nil
@@ -132,7 +150,7 @@ module TinyServer
debug_info = {:message => "no data matches the request for #{env['REQUEST_URI']}",
:available_routes => @routes, :request => env}
# Uncomment me for glorious debugging
- #pp :not_found => debug_info
+ # pp :not_found => debug_info
[404, {'Content-Type' => 'application/json'}, debug_info.to_json]
end
end
@@ -152,6 +170,7 @@ module TinyServer
end
def matches_request?(uri)
+ uri = URI.parse(uri).request_uri
@path_spec === uri
end
@@ -171,7 +190,7 @@ module TinyServer
def call
data = @data || @block.call
- [@response_code, HEADERS, data]
+ [@response_code, HEADERS, Array(data)]
end
def to_s