summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRick Bradley <rick@rickbradley.com>2007-10-06 10:38:22 -0500
committerRick Bradley <rick@rickbradley.com>2007-10-06 10:38:22 -0500
commit1befcc46926a27ec5f799d6ad8caa59c3b808c4c (patch)
tree71f3d553f38a1f3c873038dcd26d2376064ee6b6
parentb6dc1aef001c08b0589d041f6f5e3680c8b295fb (diff)
downloadpuppet-1befcc46926a27ec5f799d6ad8caa59c3b808c4c.tar.gz
puppet-1befcc46926a27ec5f799d6ad8caa59c3b808c4c.tar.xz
puppet-1befcc46926a27ec5f799d6ad8caa59c3b808c4c.zip
Homing in on a clean separation of concerns for a low-coupling, high-cohesion "server" model that will handle REST and/or XMLRPC on webrick and/or mongrel.
-rw-r--r--spec/unit/network/rest_controller.rb55
-rw-r--r--spec/unit/network/server.rb19
2 files changed, 64 insertions, 10 deletions
diff --git a/spec/unit/network/rest_controller.rb b/spec/unit/network/rest_controller.rb
index 86bdd8b58..0bcc0abf2 100644
--- a/spec/unit/network/rest_controller.rb
+++ b/spec/unit/network/rest_controller.rb
@@ -8,7 +8,58 @@ require File.dirname(__FILE__) + '/../../spec_helper'
require 'puppet/network/rest_controller'
describe Puppet::Network::RESTController, "in general" do
- it "should take arguments from server, call the appropriate method with correct arguments (parameter passing)"
+ it "should route GET requests on indirector's name to indirector find for the model class"
+ it "should route GET requests on indirector's plural name to indirector search for the model class"
+ it "should route DELETE requests on indirector's name to indirector destroy for the model class"
+ it "should route POST requests on indirector's name to indirector save for the model class"
it "should serialize result data when methods are handled"
- it "should serialize an error condition when indirection method call generates an exception"
+ it "should serialize an error condition when indirection method call generates an exception"
+end
+
+__END__
+
+# possible implementation of the satisfying class
+
+class RESTController
+ def initialize(klass)
+ @klass = klass
+ end
+
+ # TODO: is it possible to distinguish from the request object the path which we were called by?
+
+ def do_GET(request, response)
+ return do_GETS(request, response) if asked_for_plural?(request)
+ args = request.something
+ result = @klass.find args
+ return serialize(result)
+ end
+
+ def do_GETS(request, response)
+ args = request.something
+ result = @klass.search args
+ return serialize(result)
+ end
+
+ def do_DELETE(request, response)
+ args = request.something
+ result = @klass.destroy args
+ return serialize(result)
+ end
+
+ def do_PUT(request, response)
+ args = request.something
+ obj = @klass.new(args)
+ result = obj.save
+ return serialize(result)
+ end
+
+ def do_POST(request, response)
+ do_PUT(request, response)
+ end
+
+ private
+
+ def asked_for_plural?(request)
+ # TODO: pick apart the request and see if this was trying to do a plural or singular GET
+ end
end
diff --git a/spec/unit/network/server.rb b/spec/unit/network/server.rb
index 5a1980fec..17ed336de 100644
--- a/spec/unit/network/server.rb
+++ b/spec/unit/network/server.rb
@@ -32,6 +32,9 @@ describe Puppet::Network::Server, "when initializing" do
Proc.new { Puppet::Network::Server.new }.should raise_error
end
+ it "should use the Puppet Configurator to determine what style of service we will offer to clients (e.g., REST, XMLRPC, ...)"
+ it "should fail to initialize if there is no style of service known to the Puppet configurator"
+
it "should allow registering indirections" do
@server = Puppet::Network::Server.new(:handlers => [ :foo, :bar, :baz])
Proc.new { @server.unregister(:foo, :bar, :baz) }.should_not raise_error
@@ -103,6 +106,8 @@ describe Puppet::Network::Server, "in general" do
it "should provide a means of determining which HTTP server will be used to provide access to clients" do
@server.server_type.should == :suparserver
end
+
+ it "should provide a means of determining which style of service is being offered to clients"
it "should allow for multiple configurations, each handling different indirections" do
@server2 = Puppet::Network::Server.new
@@ -139,10 +144,9 @@ describe Puppet::Network::Server, "when listening is turned off" do
@server.listen
end
- it "should not route HTTP GET requests on indirector's name to indirector find for the specified HTTP server"
- it "should not route HTTP GET requests on indirector's plural name to indirector search for the specified HTTP server"
- it "should not route HTTP DELETE requests on indirector's name to indirector destroy for the specified HTTP server"
- it "should not route HTTP POST requests on indirector's name to indirector save for the specified HTTP server"
+ it "should not route HTTP GET requests to a controller for the registered indirection"
+ it "should not route HTTP DELETE requests to a controller for the registered indirection"
+ it "should not route HTTP POST requests to a controller for the registered indirection"
# TODO: FIXME write integrations which fire up actual webrick / mongrel servers and are thus webrick / mongrel specific?]
end
@@ -172,10 +176,9 @@ describe Puppet::Network::Server, "when listening is turned on" do
@server.unlisten
end
- it "should route HTTP GET requests on indirector's name to indirector find for the specified HTTP server"
- it "should route HTTP GET requests on indirector's plural name to indirector search for the specified HTTP server"
- it "should route HTTP DELETE requests on indirector's name to indirector destroy for the specified HTTP server"
- it "should route HTTP POST requests on indirector's name to indirector save for the specified HTTP server"
+ it "should route HTTP GET requests to a controller for the registered indirection"
+ it "should route HTTP DELETE requests to a controller for the registered indirection"
+ it "should route HTTP POST requests to a controller for the registered indirection"
# TODO: FIXME [ write integrations which fire up actual webrick / mongrel servers and are thus webrick / mongrel specific?]
end