summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2007-10-15 15:29:00 -0500
committerRick Bradley <rick@rickbradley.com>2007-10-15 15:29:00 -0500
commitba952029b057cb64cf28d9e4dfb5c78868a4b53f (patch)
tree2e7841459707683a967dcb5c51e445eaea0cd172 /spec
parentef8ebe0df4da0a0cd2f599308f40bd707ab18d92 (diff)
downloadpuppet-ba952029b057cb64cf28d9e4dfb5c78868a4b53f.tar.gz
puppet-ba952029b057cb64cf28d9e4dfb5c78868a4b53f.tar.xz
puppet-ba952029b057cb64cf28d9e4dfb5c78868a4b53f.zip
Partial support for building Handlers for all handler-protocol pairs.
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/network/http/mongrel.rb36
-rw-r--r--spec/unit/network/http/webrick.rb23
2 files changed, 50 insertions, 9 deletions
diff --git a/spec/unit/network/http/mongrel.rb b/spec/unit/network/http/mongrel.rb
index f964e6844..6c8b65582 100644
--- a/spec/unit/network/http/mongrel.rb
+++ b/spec/unit/network/http/mongrel.rb
@@ -18,7 +18,7 @@ describe Puppet::Network::HTTP::Mongrel, "when turning on listening" do
@mock_mongrel = mock('mongrel')
@mock_mongrel.stubs(:run)
Mongrel::HttpServer.stubs(:new).returns(@mock_mongrel)
- @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => { :foo => :bar }}
+ @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => [ :node, :configuration ], :protocols => [ :rest, :xmlrpc ] }
end
it "should fail if already listening" do
@@ -30,6 +30,10 @@ describe Puppet::Network::HTTP::Mongrel, "when turning on listening" do
Proc.new { @server.listen(@listen_params.delete_if {|k,v| :handlers == k}) }.should raise_error(ArgumentError)
end
+ it "should require at least one protocol" do
+ Proc.new { @server.listen(@listen_params.delete_if {|k,v| :protocols == k}) }.should raise_error(ArgumentError)
+ end
+
it "should require a listening address to be specified" do
Proc.new { @server.listen(@listen_params.delete_if {|k,v| :address == k})}.should raise_error(ArgumentError)
end
@@ -56,8 +60,31 @@ describe Puppet::Network::HTTP::Mongrel, "when turning on listening" do
@server.should be_listening
end
- it "should instantiate a specific handler (mongrel+rest, e.g.) for each handler, for each protocol being served (xmlrpc, rest, etc.)"
- it "should mount handlers on a mongrel path"
+ it "should instantiate a specific handler (mongrel+rest, e.g.) for each named handler, for each named protocol)" do
+ @listen_params[:handlers].each do |handler|
+ @listen_params[:protocols].each do |protocol|
+ mock_handler = mock("handler instance for [#{protocol}]+[#{handler}]")
+ mock_handler_class = mock("handler class for [#{protocol}]+[#{handler}]")
+ mock_handler_class.expects(:new).returns(mock_handler)
+ @server.expects(:class_for_protocol_handler).with(protocol, handler).returns(mock_handler_class)
+ end
+ end
+ @server.listen(@listen_params)
+ end
+
+ it "should mount each handler on a mongrel path" do
+ pending "a moment of clarity"
+ @listen_params[:handlers].each do |handler|
+ @listen_params[:protocols].each do |protocol|
+ mock_handler = mock("handler instance for [#{protocol}]+[#{handler}]")
+ mock_handler_class = mock("handler class for [#{protocol}]+[#{handler}]")
+ mock_handler_class.stubs(:new).returns(mock_handler)
+ @server.stubs(:class_for_protocol_handler).with(protocol, handler).returns(mock_handler_class)
+ # TODO / FIXME : HERE -- need to begin resolving the model behind the indirection
+ end
+ end
+ @server.listen(@listen_params)
+ end
end
describe Puppet::Network::HTTP::Mongrel, "when turning off listening" do
@@ -65,9 +92,8 @@ describe Puppet::Network::HTTP::Mongrel, "when turning off listening" do
@mock_mongrel = mock('mongrel httpserver')
@mock_mongrel.stubs(:run)
Mongrel::HttpServer.stubs(:new).returns(@mock_mongrel)
-
@server = Puppet::Network::HTTP::Mongrel.new
- @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => { :foo => :bar }}
+ @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => [ :node, :configuration ], :protocols => [ :rest, :xmlrpc ] }
end
it "should fail unless listening" do
diff --git a/spec/unit/network/http/webrick.rb b/spec/unit/network/http/webrick.rb
index 804be4c33..b94a6a78d 100644
--- a/spec/unit/network/http/webrick.rb
+++ b/spec/unit/network/http/webrick.rb
@@ -19,7 +19,7 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
@mock_webrick = mock('webrick')
WEBrick::HTTPServer.stubs(:new).returns(@mock_webrick)
@server = Puppet::Network::HTTP::WEBrick.new
- @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => { :foo => :bar }}
+ @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => [ :node, :configuration ], :protocols => [ :rest, :xmlrpc ] }
end
it "should fail if already listening" do
@@ -31,6 +31,10 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
Proc.new { @server.listen(@listen_params.delete_if {|k,v| :handlers == k}) }.should raise_error(ArgumentError)
end
+ it "should require at least one protocol" do
+ Proc.new { @server.listen(@listen_params.delete_if {|k,v| :protocols == k}) }.should raise_error(ArgumentError)
+ end
+
it "should require a listening address to be specified" do
Proc.new { @server.listen(@listen_params.delete_if {|k,v| :address == k})}.should raise_error(ArgumentError)
end
@@ -55,8 +59,19 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
@server.listen(@listen_params)
@server.should be_listening
end
-
- it "should instantiate a specific handler (webrick+rest, e.g.) for each handler, for each protocol being served (xmlrpc, rest, etc.)"
+
+ it "should instantiate a specific handler (mongrel+rest, e.g.) for each named handler, for each named protocol)" do
+ @listen_params[:handlers].each do |handler|
+ @listen_params[:protocols].each do |protocol|
+ mock_handler = mock("handler instance for [#{protocol}]+[#{handler}]")
+ mock_handler_class = mock("handler class for [#{protocol}]+[#{handler}]")
+ mock_handler_class.expects(:new).returns(mock_handler)
+ @server.expects(:class_for_protocol_handler).with(protocol, handler).returns(mock_handler_class)
+ end
+ end
+ @server.listen(@listen_params)
+ end
+
it "should mount handlers on a webrick path"
end
@@ -68,7 +83,7 @@ describe Puppet::Network::HTTP::WEBrick, "when turning off listening" do
WEBrick::HTTPServer.stubs(:new).returns(@mock_webrick)
@server = Puppet::Network::HTTP::WEBrick.new
@server.stubs(:shutdown)
- @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => { :foo => :bar }}
+ @listen_params = { :address => "127.0.0.1", :port => 31337, :handlers => [ :node, :configuration ], :protocols => [ :rest, :xmlrpc ] }
end
it "should fail unless listening" do