summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2007-10-16 10:15:14 -0500
committerRick Bradley <rick@rickbradley.com>2007-10-16 10:15:14 -0500
commitc06edda4c94ef9aa685ed44d7031bb39c4a2b0cc (patch)
treec8fedbe14686ac205c212258ac526cd6483982c8 /spec
parentab4c7fa825e0d1f702adc215c7ff6d445d3b6559 (diff)
downloadpuppet-c06edda4c94ef9aa685ed44d7031bb39c4a2b0cc.tar.gz
puppet-c06edda4c94ef9aa685ed44d7031bb39c4a2b0cc.tar.xz
puppet-c06edda4c94ef9aa685ed44d7031bb39c4a2b0cc.zip
First pass through initializers of {mongrel, webrick} REST handlers; hooks into Indirection to look up models from indirected names.
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/indirector/indirection.rb14
-rw-r--r--spec/unit/network/http/mongrel.rb8
-rw-r--r--spec/unit/network/http/mongrel/rest.rb46
-rw-r--r--spec/unit/network/http/mongrel/xmlrpc.rb0
-rw-r--r--spec/unit/network/http/webrick.rb8
-rw-r--r--spec/unit/network/http/webrick/rest.rb46
-rw-r--r--spec/unit/network/http/webrick/xmlrpc.rb0
-rw-r--r--spec/unit/network/server.rb17
8 files changed, 111 insertions, 28 deletions
diff --git a/spec/unit/indirector/indirection.rb b/spec/unit/indirector/indirection.rb
index 455b5dc67..cb1b4b8e8 100755
--- a/spec/unit/indirector/indirection.rb
+++ b/spec/unit/indirector/indirection.rb
@@ -23,7 +23,7 @@ describe Puppet::Indirector::Indirection do
@indirection.find(@name).should == @instance
end
- it "should handle removing model instances from a terminus letting the appropriate terminus remove the instance" do
+ it "should handle removing model instances from a terminus by letting the appropriate terminus remove the instance" do
@terminus.expects(:destroy).with(@name).returns(@instance)
@indirection.destroy(@name).should == @instance
end
@@ -103,11 +103,21 @@ describe Puppet::Indirector::Indirection, " when managing indirection instances"
@indirection = Puppet::Indirector::Indirection.new(mock('model'), :test)
Puppet::Indirector::Indirection.instance(:test).should equal(@indirection)
end
-
+
it "should return nil when the named indirection has not been created" do
Puppet::Indirector::Indirection.instance(:test).should be_nil
end
+ it "should allow an indirection's model to be retrieved by name" do
+ mock_model = mock('model')
+ @indirection = Puppet::Indirector::Indirection.new(mock_model, :test)
+ Puppet::Indirector::Indirection.model(:test).should equal(mock_model)
+ end
+
+ it "should return nil when no model matches the requested name" do
+ Puppet::Indirector::Indirection.model(:test).should be_nil
+ end
+
after do
@indirection.delete if defined? @indirection
end
diff --git a/spec/unit/network/http/mongrel.rb b/spec/unit/network/http/mongrel.rb
index 161080109..3364efb92 100644
--- a/spec/unit/network/http/mongrel.rb
+++ b/spec/unit/network/http/mongrel.rb
@@ -64,11 +64,9 @@ describe Puppet::Network::HTTP::Mongrel, "when turning on listening" do
@listen_params[:protocols].each do |protocol|
mock_handler = mock("handler instance for [#{protocol}]")
mock_handler_class = mock("handler class for [#{protocol}]")
- @listen_params[:handlers].each do |handler|
- mock_handler_class.expects(:new).with {|args|
- args[:server] == @mock_mongrel and args[:handler] == handler
- }.returns(mock_handler)
- end
+ mock_handler_class.expects(:new).with {|args|
+ args[:server] == @mock_mongrel and args[:handlers] == @listen_params[:handlers]
+ }.returns(mock_handler)
@server.expects(:class_for_protocol).with(protocol).at_least_once.returns(mock_handler_class)
end
@server.listen(@listen_params)
diff --git a/spec/unit/network/http/mongrel/rest.rb b/spec/unit/network/http/mongrel/rest.rb
new file mode 100644
index 000000000..4a6524ef6
--- /dev/null
+++ b/spec/unit/network/http/mongrel/rest.rb
@@ -0,0 +1,46 @@
+#!/usr/bin/env ruby
+#
+# Created by Rick Bradley on 2007-10-16.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+require 'puppet/network/http'
+
+describe Puppet::Network::HTTP::MongrelREST, "when initializing" do
+ before do
+ @mock_mongrel = mock('Mongrel server')
+ @params = { :server => @mock_mongrel, :handlers => [ :foo ] }
+ end
+
+ it "should require access to a Mongrel server" do
+ Proc.new { Puppet::Network::HTTP::MongrelREST.new(@params.delete_if {|k,v| :server == k })}.should raise_error(ArgumentError)
+ end
+
+ it "should require at least one indirection name" do
+ Proc.new { Puppet::Network::HTTP::MongrelREST.new(@params.delete_if {|k,v| :handlers == k })}.should raise_error(ArgumentError)
+ end
+
+ it "should look up the indirection model from the indirection name" do
+ mock_model = mock('indirected model')
+ Puppet::Indirector::Indirection.expects(:model).with(:foo).returns(mock_model)
+ Puppet::Network::HTTP::MongrelREST.new(@params)
+ end
+
+ it "should fail if a handler is not indirected" do
+ Puppet::Indirector::Indirection.expects(:model).with(:foo).returns(nil)
+ Proc.new { Puppet::Network::HTTP::MongrelREST.new(@params) }.should raise_error(ArgumentError)
+ end
+
+ it "should register a listener for each indirection with the provided Mongrel server"
+end
+
+describe Puppet::Network::HTTP::MongrelREST, "when receiving a request" do
+ it "should unpack request information from Mongrel"
+ it "should unpack parameters from the request for passing to controller methods"
+ it "should call the controller find method if the request represents a singular HTTP GET"
+ it "should call the controller search method if the request represents a plural HTTP GET"
+ it "should call the controller destroy method if the request represents an HTTP DELETE"
+ it "should call the controller save method if the request represents an HTTP PUT"
+ it "should serialize the result from the controller method for return back to Mongrel"
+ it "should serialize a controller expection result for return back to Mongrel"
+end
diff --git a/spec/unit/network/http/mongrel/xmlrpc.rb b/spec/unit/network/http/mongrel/xmlrpc.rb
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/spec/unit/network/http/mongrel/xmlrpc.rb
diff --git a/spec/unit/network/http/webrick.rb b/spec/unit/network/http/webrick.rb
index 81b2a0fa9..4bf742b6e 100644
--- a/spec/unit/network/http/webrick.rb
+++ b/spec/unit/network/http/webrick.rb
@@ -64,11 +64,9 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do
@listen_params[:protocols].each do |protocol|
mock_handler = mock("handler instance for [#{protocol}]")
mock_handler_class = mock("handler class for [#{protocol}]")
- @listen_params[:handlers].each do |handler|
- mock_handler_class.expects(:new).with {|args|
- args[:server] == @mock_webrick and args[:handler] == handler
- }.returns(mock_handler)
- end
+ mock_handler_class.expects(:new).with {|args|
+ args[:server] == @mock_webrick and args[:handlers] == @listen_params[:handlers]
+ }.returns(mock_handler)
@server.expects(:class_for_protocol).with(protocol).at_least_once.returns(mock_handler_class)
end
@server.listen(@listen_params)
diff --git a/spec/unit/network/http/webrick/rest.rb b/spec/unit/network/http/webrick/rest.rb
new file mode 100644
index 000000000..f17f89a15
--- /dev/null
+++ b/spec/unit/network/http/webrick/rest.rb
@@ -0,0 +1,46 @@
+#!/usr/bin/env ruby
+#
+# Created by Rick Bradley on 2007-10-16.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../../../spec_helper'
+require 'puppet/network/http'
+
+describe Puppet::Network::HTTP::WEBrickREST, "when initializing" do
+ before do
+ @mock_webrick = mock('WEBrick server')
+ @params = { :server => @mock_webrick, :handlers => [ :foo ] }
+ end
+
+ it "should require access to a WEBrick server" do
+ Proc.new { Puppet::Network::HTTP::WEBrickREST.new(@params.delete_if {|k,v| :server == k })}.should raise_error(ArgumentError)
+ end
+
+ it "should require at least one indirection name" do
+ Proc.new { Puppet::Network::HTTP::WEBrickREST.new(@params.delete_if {|k,v| :handlers == k })}.should raise_error(ArgumentError)
+ end
+
+ it "should look up the indirection model from the indirection name" do
+ mock_model = mock('indirected model')
+ Puppet::Indirector::Indirection.expects(:model).with(:foo).returns(mock_model)
+ Puppet::Network::HTTP::WEBrickREST.new(@params)
+ end
+
+ it "should fail if a handler is not indirected" do
+ Puppet::Indirector::Indirection.expects(:model).with(:foo).returns(nil)
+ Proc.new { Puppet::Network::HTTP::WEBrickREST.new(@params) }.should raise_error(ArgumentError)
+ end
+
+ it "should register a listener for each indirection with the provided WEBrick server"
+end
+
+describe Puppet::Network::HTTP::WEBrickREST, "when receiving a request" do
+ it "should unpack request information from WEBrick"
+ it "should unpack parameters from the request for passing to controller methods"
+ it "should call the controller find method if the request represents a singular HTTP GET"
+ it "should call the controller search method if the request represents a plural HTTP GET"
+ it "should call the controller destroy method if the request represents an HTTP DELETE"
+ it "should call the controller save method if the request represents an HTTP PUT"
+ it "should serialize the result from the controller method for return back to Mongrel"
+ it "should serialize a controller expection result for return back to Mongrel"
+end
diff --git a/spec/unit/network/http/webrick/xmlrpc.rb b/spec/unit/network/http/webrick/xmlrpc.rb
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/spec/unit/network/http/webrick/xmlrpc.rb
diff --git a/spec/unit/network/server.rb b/spec/unit/network/server.rb
index 659eb1930..97ab4443a 100644
--- a/spec/unit/network/server.rb
+++ b/spec/unit/network/server.rb
@@ -273,25 +273,10 @@ describe Puppet::Network::Server, "when listening is being turned off" do
end
- # TODO / FIXME : HERE -- need to begin resolving the model behind the indirection
- # looks like: get the handler class, providing @server to it
- # have the handler class register the handler @ the right URL
- # handler class knows the correct path to use, correct registration method to call
- # handler also know how to get the model class from the indirection name
- # do we change indirection name to indirection (instead of saying "handlers")?
-
-
-describe Class.new, "Puppet::Network::Handler::*::* (handler class (e.g., webrick+rest or mongrel+xmlrpc))" do
- it "should be able to unserialize a request from the given httpserver answering for the given protocol handler, to be used by a controller"
- it "should be able to serialize a result from a controller for return by the given httpserver responding with the given protocol"
- it "should properly encode an exception from a controller for use by the httpserver for the given protocol handler"
- it "should call the appropriate controller method"
- it "should properly encode parameters on the request for use by the controller methods"
-end
-
describe Class.new, "put these somewhere" do
it "should allow indirections to deny access to services based upon which client is connecting, or whether the client is authorized"
it "should deny access to clients based upon rules"
end
+