summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/network/rest_server.rb15
-rw-r--r--spec/unit/network/rest_server.rb43
2 files changed, 54 insertions, 4 deletions
diff --git a/lib/puppet/network/rest_server.rb b/lib/puppet/network/rest_server.rb
index 0ffa8ff16..7c745f321 100644
--- a/lib/puppet/network/rest_server.rb
+++ b/lib/puppet/network/rest_server.rb
@@ -1,5 +1,6 @@
class Puppet::Network::RESTServer # :nodoc:
@@routes = {}
+ @@listening = false
def self.register(*indirections)
raise ArgumentError, "indirection names are required" if indirections.empty?
@@ -17,4 +18,18 @@ class Puppet::Network::RESTServer # :nodoc:
def self.reset
self.unregister(@@routes.keys) unless @@routes.keys.empty?
end
+
+ def self.listening?
+ @@listening
+ end
+
+ def self.listen
+ raise "Cannot listen -- already listening" if @@listening
+ @@listening = true
+ end
+
+ def self.unlisten
+ raise "Cannot unlisten -- not currently listening" unless @@listening
+ @@listening = false
+ end
end
diff --git a/spec/unit/network/rest_server.rb b/spec/unit/network/rest_server.rb
index 986f95239..974cf17e9 100644
--- a/spec/unit/network/rest_server.rb
+++ b/spec/unit/network/rest_server.rb
@@ -66,12 +66,30 @@ describe Puppet::Network::RESTServer, "in general" do
end
Puppet::Network::RESTServer.reset
end
+
+ it "should provide a means of determining whether it is providing access to clients" do
+ Puppet::Network::RESTServer.should respond_to(:listening?)
+ end
end
describe Puppet::Network::RESTServer, "when listening is not turned on" do
+ before do
+ Puppet::Network::RESTServer.unlisten if Puppet::Network::RESTServer.listening?
+ end
+
+ it "should allow listening to be turned on" do
+ Proc.new { Puppet::Network::RESTServer.listen }.should_not raise_error
+ end
+
+ it "should not allow listening to be turned off" do
+ Proc.new { Puppet::Network::RESTServer.unlisten }.should raise_error(RuntimeError)
+ end
+
+ it "should indicate that it is not listening" do
+ Puppet::Network::RESTServer.should_not be_listening
+ end
+
it "should allow picking which technology to use to make indirections accessible to clients"
- it "should allow listening to be turned on"
- it "should not allow listening to be turned off"
it "should not route HTTP GET requests on indirector's name to indirector find for the specified technology"
it "should not route HTTP GET requests on indirector's plural name to indirector search for the specified technology"
it "should not route HTTP DELETE requests on indirector's name to indirector destroy for the specified technology"
@@ -81,9 +99,23 @@ describe Puppet::Network::RESTServer, "when listening is not turned on" do
end
describe Puppet::Network::RESTServer, "when listening is turned on" do
+ before do
+ Puppet::Network::RESTServer.listen unless Puppet::Network::RESTServer.listening?
+ end
+
+ it "should allow listening to be turned off" do
+ Proc.new { Puppet::Network::RESTServer.unlisten }.should_not raise_error
+ end
+
+ it "should not allow listening to be turned on" do
+ Proc.new { Puppet::Network::RESTServer.listen }.should raise_error(RuntimeError)
+ end
+
+ it "should indicate that it is listening" do
+ Puppet::Network::RESTServer.should be_listening
+ end
+
it "should not allow picking which technology to use to make indirections accessible to clients"
- it "should allow listening to be turned off"
- it "should not allow listening to be turned on"
it "should route HTTP GET requests on indirector's name to indirector find for the specified technology"
it "should route HTTP GET requests on indirector's plural name to indirector search for the specified technology"
it "should route HTTP DELETE requests on indirector's name to indirector destroy for the specified technology"
@@ -91,3 +123,6 @@ describe Puppet::Network::RESTServer, "when listening is turned on" do
# TODO: FIXME [ write integrations which fire up actual webrick / mongrel servers and are thus webrick / mongrel specific?]
end
+
+
+# TODO: FIXME == should be able to have multiple servers running on different technologies, or with different configurations -- this will force an instance model