From fd841b33a2920f26d472f4f38a559d8f2aa48a0c Mon Sep 17 00:00:00 2001 From: Rick Bradley Date: Thu, 4 Oct 2007 13:00:13 -0500 Subject: Updating first portion of the Network RESTServer spec with example code, getting the added examples to pass. --- lib/puppet/network/rest_server.rb | 18 ++++++++++++++++ spec/unit/network/rest_server.rb | 44 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/lib/puppet/network/rest_server.rb b/lib/puppet/network/rest_server.rb index e415e8bcb..0ffa8ff16 100644 --- a/lib/puppet/network/rest_server.rb +++ b/lib/puppet/network/rest_server.rb @@ -1,2 +1,20 @@ class Puppet::Network::RESTServer # :nodoc: + @@routes = {} + + def self.register(*indirections) + raise ArgumentError, "indirection names are required" if indirections.empty? + indirections.flatten.each { |i| @@routes[i.to_sym] = true } + end + + def self.unregister(*indirections) + raise ArgumentError, "indirection names are required" if indirections.empty? + indirections.flatten.each do |i| + raise(ArgumentError, "indirection [%s] is not known" % i) unless @@routes[i.to_sym] + @@routes.delete(i.to_sym) + end + end + + def self.reset + self.unregister(@@routes.keys) unless @@routes.keys.empty? + end end diff --git a/spec/unit/network/rest_server.rb b/spec/unit/network/rest_server.rb index 156e11b08..d18086fff 100644 --- a/spec/unit/network/rest_server.rb +++ b/spec/unit/network/rest_server.rb @@ -8,8 +8,48 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/network/rest_server' describe Puppet::Network::RESTServer, "in general" do - it "should provide a way to specify that an indirection is to be made accessible to clients" - it "should provide a way to specify that an indirection is to no longer be made accessible to clients" + before do + Puppet::Network::RESTServer.reset + end + + it "should allow registering an indirection for client access by specifying its indirection name" do + Proc.new { Puppet::Network::RESTServer.register(:foo) }.should_not raise_error + end + + it "should require at least one indirection name when registering indirections for client access" do + Proc.new { Puppet::Network::RESTServer.register }.should raise_error(ArgumentError) + end + + it "should allow for numerous indirections to be registered at once for client access" do + Proc.new { Puppet::Network::RESTServer.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 + Puppet::Network::RESTServer.register(:foo) + Proc.new { Puppet::Network::RESTServer.unregister(:foo) }.should_not raise_error + end + + it "should leave other indirections accessible to clients when turning off other indirections" do + Puppet::Network::RESTServer.register(:foo, :bar) + Puppet::Network::RESTServer.unregister(:foo) + Proc.new { Puppet::Network::RESTServer.unregister(:bar)}.should_not raise_error + end + + it "should allow specifying numerous indirections which are to be no longer accessible to clients" do + Puppet::Network::RESTServer.register(:foo, :bar) + Proc.new { Puppet::Network::RESTServer.unregister(:foo, :bar) }.should_not raise_error + end + + it "should not allow for unregistering unknown indirection names" do + Puppet::Network::RESTServer.register(:foo, :bar) + Proc.new { Puppet::Network::RESTServer.unregister(:baz) }.should raise_error(ArgumentError) + end + + it "should disable client access immediately" do + Puppet::Network::RESTServer.register(:foo, :bar) + Puppet::Network::RESTServer.unregister(:foo) + Proc.new { Puppet::Network::RESTServer.unregister(:foo) }.should raise_error(ArgumentError) + end end describe Puppet::Network::RESTServer, "when listening is not turned on" do -- cgit