summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/indirector/rest.rb30
-rwxr-xr-xspec/unit/indirector/rest/node.rb13
-rw-r--r--spec/unit/network/rest_controller.rb65
-rw-r--r--spec/unit/network/server.rb184
4 files changed, 292 insertions, 0 deletions
diff --git a/spec/unit/indirector/rest.rb b/spec/unit/indirector/rest.rb
new file mode 100755
index 000000000..cf29577b9
--- /dev/null
+++ b/spec/unit/indirector/rest.rb
@@ -0,0 +1,30 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+require 'puppet/indirector/rest'
+
+describe Puppet::Indirector::REST do
+ # FIXME : TODO / look through this, does this make sense?
+ before do
+ Puppet::Indirector::Terminus.stubs(:register_terminus_class)
+ @model = mock 'model'
+ @indirection = stub 'indirection', :name => :mystuff, :register_terminus_type => nil, :model => @model
+ Puppet::Indirector::Indirection.stubs(:instance).returns(@indirection)
+
+ @rest_class = Class.new(Puppet::Indirector::REST) do
+ def self.to_s
+ "Testing"
+ end
+ end
+
+ @searcher = @rest_class.new
+ end
+
+ it "should return an instance of the indirected model"
+ it "should deserialize result data after a call into a Model instance for find"
+ it "should deserialize result data after a call into a list of Model instances for search"
+ it "should deserialize result data after a call into a boolean for save"
+ it "should deserialize result data after a call into a boolean for destroy"
+ it "should generate an error when result data deserializes improperly"
+ it "should generate an error when result data specifies an error"
+end
diff --git a/spec/unit/indirector/rest/node.rb b/spec/unit/indirector/rest/node.rb
new file mode 100755
index 000000000..c78556ada
--- /dev/null
+++ b/spec/unit/indirector/rest/node.rb
@@ -0,0 +1,13 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+require 'puppet/indirector/rest/node'
+
+describe Puppet::Indirector::REST::Node do
+ before do
+ @searcher = Puppet::Indirector::REST::Node.new
+ end
+
+
+end
diff --git a/spec/unit/network/rest_controller.rb b/spec/unit/network/rest_controller.rb
new file mode 100644
index 000000000..0bcc0abf2
--- /dev/null
+++ b/spec/unit/network/rest_controller.rb
@@ -0,0 +1,65 @@
+#!/usr/bin/env ruby
+#
+# Created by Rick Bradley on 2007-10-03.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/network/rest_controller'
+
+describe Puppet::Network::RESTController, "in general" do
+ 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"
+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
new file mode 100644
index 000000000..17ed336de
--- /dev/null
+++ b/spec/unit/network/server.rb
@@ -0,0 +1,184 @@
+#!/usr/bin/env ruby
+#
+# Created by Rick Bradley on 2007-10-03.
+# Copyright (c) 2007. All rights reserved.
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/network/server'
+
+# a fake server class, so we don't have to implement full autoloading etc. (or at least just yet) just to do testing
+class TestServer < Puppet::Network::Server
+ def start_web_server
+ end
+
+ def stop_web_server
+ end
+end
+
+describe Puppet::Network::Server, "when initializing" do
+ before do
+ Puppet::Network::Server.stubs(:server_class_by_name).returns(TestServer)
+ end
+
+ it "should use the Puppet configurator to determine which HTTP server will be used to provide access to clients" do
+ Puppet.expects(:[]).with(:servertype).returns(:suparserver)
+ @server = Puppet::Network::Server.new
+ @server.server_type.should == :suparserver
+ end
+
+ it "should fail to initialize if there is no HTTP server known to the Puppet configurator" do
+ Puppet.expects(:[]).with(:servertype).returns(nil)
+ 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
+ end
+
+ it "should not be listening after initialization" do
+ Puppet::Network::Server.new.should_not be_listening
+ end
+end
+
+describe Puppet::Network::Server, "in general" do
+ before do
+ Puppet::Network::Server.stubs(:server_class_by_name).returns(TestServer)
+ Puppet.stubs(:[]).with(:servertype).returns(:suparserver)
+ @server = Puppet::Network::Server.new
+ end
+
+ it "should allow registering an indirection for client access by specifying its indirection name" do
+ Proc.new { @server.register(:foo) }.should_not raise_error
+ end
+
+ it "should require at least one indirection name when registering indirections for client access" do
+ Proc.new { @server.register }.should raise_error(ArgumentError)
+ end
+
+ it "should allow for numerous indirections to be registered at once for client access" do
+ Proc.new { @server.register(:foo, :bar, :baz) }.should_not raise_error
+ end
+
+ it "should allow the use of indirection names to specify which indirections are to be no longer accessible to clients" do
+ @server.register(:foo)
+ Proc.new { @server.unregister(:foo) }.should_not raise_error
+ end
+
+ it "should leave other indirections accessible to clients when turning off indirections" do
+ @server.register(:foo, :bar)
+ @server.unregister(:foo)
+ Proc.new { @server.unregister(:bar)}.should_not raise_error
+ end
+
+ it "should allow specifying numerous indirections which are to be no longer accessible to clients" do
+ @server.register(:foo, :bar)
+ Proc.new { @server.unregister(:foo, :bar) }.should_not raise_error
+ end
+
+ it "should not allow turning off unknown indirection names" do
+ @server.register(:foo, :bar)
+ Proc.new { @server.unregister(:baz) }.should raise_error(ArgumentError)
+ end
+
+ it "should disable client access immediately when turning off indirections" do
+ @server.register(:foo, :bar)
+ @server.unregister(:foo)
+ Proc.new { @server.unregister(:foo) }.should raise_error(ArgumentError)
+ end
+
+ it "should allow turning off all indirections at once" do
+ @server.register(:foo, :bar)
+ @server.unregister
+ [ :foo, :bar, :baz].each do |indirection|
+ Proc.new { @server.unregister(indirection) }.should raise_error(ArgumentError)
+ end
+ end
+
+ it "should provide a means of determining whether it is listening" do
+ @server.should respond_to(:listening?)
+ end
+
+ 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
+ @server.register(:foo, :bar)
+ @server2.register(:foo, :xyzzy)
+ @server.unregister(:foo, :bar)
+ @server2.unregister(:foo, :xyzzy)
+ Proc.new { @server.unregister(:xyzzy) }.should raise_error(ArgumentError)
+ Proc.new { @server2.unregister(:bar) }.should raise_error(ArgumentError)
+ end
+end
+
+describe Puppet::Network::Server, "when listening is turned off" do
+ before do
+ Puppet::Network::Server.stubs(:server_class_by_name).returns(TestServer)
+ Puppet.stubs(:[]).with(:servertype).returns(:suparserver)
+ @server = Puppet::Network::Server.new
+ end
+
+ it "should allow listening to be turned on" do
+ Proc.new { @server.listen }.should_not raise_error
+ end
+
+ it "should not allow listening to be turned off" do
+ Proc.new { @server.unlisten }.should raise_error(RuntimeError)
+ end
+
+ it "should indicate that it is not listening" do
+ @server.should_not be_listening
+ end
+
+ it "should cause the HTTP server to listen when listening is turned on" do
+ @server.expects(:start_web_server)
+ @server.listen
+ end
+
+ 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
+
+describe Puppet::Network::Server, "when listening is turned on" do
+ before do
+ Puppet::Network::Server.stubs(:server_class_by_name).returns(TestServer)
+ Puppet.stubs(:[]).with(:servertype).returns(:suparserver)
+ @server = Puppet::Network::Server.new
+ @server.listen
+ end
+
+ it "should allow listening to be turned off" do
+ Proc.new { @server.unlisten }.should_not raise_error
+ end
+
+ it "should not allow listening to be turned on" do
+ Proc.new { @server.listen }.should raise_error(RuntimeError)
+ end
+
+ it "should indicate that listening is turned off" do
+ @server.should be_listening
+ end
+
+ it "should cause the HTTP server to stop listening when listening is turned off" do
+ @server.expects(:stop_web_server)
+ @server.unlisten
+ end
+
+ 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