summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2007-10-16 00:14:02 -0500
committerRick Bradley <rick@rickbradley.com>2007-10-16 00:14:02 -0500
commitab4c7fa825e0d1f702adc215c7ff6d445d3b6559 (patch)
tree052d3b6e62a82f0954bd2befb49ceda32a2f2cb5
parent099c5469bf8fd6bf1e65be1a8192c14e584e49c3 (diff)
Minor tweaks to make the ::Server initialization a bit more robust. Fail on unknown HTTP Server types; fail fast.
-rw-r--r--lib/puppet/network/server.rb8
-rw-r--r--spec/unit/network/server.rb10
2 files changed, 13 insertions, 5 deletions
diff --git a/lib/puppet/network/server.rb b/lib/puppet/network/server.rb
index 0541c1c3b..50e3bd686 100644
--- a/lib/puppet/network/server.rb
+++ b/lib/puppet/network/server.rb
@@ -1,9 +1,9 @@
class Puppet::Network::Server
- attr_reader :server_type, :http_server_class, :protocols, :address, :port
+ attr_reader :server_type, :protocols, :address, :port
def initialize(args = {})
@server_type = Puppet[:servertype] or raise "No servertype configuration found." # e.g., WEBrick, Mongrel, etc.
- @http_server_class = http_server_class_by_type(@server_type)
+ http_server_class || raise(ArgumentError, "Could not determine HTTP Server class for server type [#{@server_type}]")
@address = args[:address] || Puppet[:bindaddress] ||
raise(ArgumentError, "Must specify :address or configure Puppet :bindaddress.")
@port = args[:port] || Puppet[:masterport] ||
@@ -47,6 +47,10 @@ class Puppet::Network::Server
http_server.unlisten
@listening = false
end
+
+ def http_server_class
+ http_server_class_by_type(@server_type)
+ end
private
diff --git a/spec/unit/network/server.rb b/spec/unit/network/server.rb
index 528d47d0e..659eb1930 100644
--- a/spec/unit/network/server.rb
+++ b/spec/unit/network/server.rb
@@ -9,8 +9,8 @@ require 'puppet/network/server'
describe Puppet::Network::Server, "when initializing" do
before do
@mock_http_server_class = mock('http server class')
- Puppet::Network::HTTP.stubs(:server_class_by_type).returns(@mock_http_server_class)
Puppet.stubs(:[]).with(:servertype).returns(:suparserver)
+ Puppet::Network::HTTP.stubs(:server_class_by_type).returns(@mock_http_server_class)
end
it "should allow specifying a listening address" do
@@ -63,10 +63,14 @@ describe Puppet::Network::Server, "when initializing" do
end
it "should ask the Puppet::Network::HTTP class to fetch the proper HTTP server class" do
- mock_http_server_class = mock('http server class')
- Puppet::Network::HTTP.expects(:server_class_by_type).with(:suparserver).returns(mock_http_server_class)
+ Puppet::Network::HTTP.expects(:server_class_by_type).with(:suparserver).returns(@mock_http_server_class)
@server = Puppet::Network::Server.new(:address => "127.0.0.1", :port => 31337)
end
+
+ it "should fail if the HTTP server class is unknown" do
+ Puppet::Network::HTTP.stubs(:server_class_by_type).returns(nil)
+ Proc.new { Puppet::Network::Server.new(:address => "127.0.0.1", :port => 31337) }.should raise_error(ArgumentError)
+ end
it "should allow registering indirections" do
@server = Puppet::Network::Server.new(:address => "127.0.0.1", :port => 31337, :handlers => [ :foo, :bar, :baz])