From 72510bfaa65e97f4eaaf246ef8f1c155716967b6 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Mon, 12 Nov 2007 22:08:44 -0600 Subject: Fixing #800 by refactoring how configurations are retrieved from the server. The real problem was getting all of the validation done before any caching, which required a good bit more refactoring than I expected. In actuality, this commit is relatively small even though it covers many files; most of the changes just make the code clearer or shorter. --- spec/unit/node/configuration.rb | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'spec/unit/node') diff --git a/spec/unit/node/configuration.rb b/spec/unit/node/configuration.rb index e9dc6b85d..5780d4fbb 100755 --- a/spec/unit/node/configuration.rb +++ b/spec/unit/node/configuration.rb @@ -301,9 +301,9 @@ end describe Puppet::Node::Configuration, " when functioning as a resource container" do before do @config = Puppet::Node::Configuration.new("host") - @one = stub 'resource1', :ref => "Me[you]", :configuration= => nil - @two = stub 'resource2', :ref => "Me[him]", :configuration= => nil - @dupe = stub 'resource3', :ref => "Me[you]", :configuration= => nil + @one = stub 'resource1', :ref => "Me[one]", :configuration= => nil + @two = stub 'resource2', :ref => "Me[two]", :configuration= => nil + @dupe = stub 'resource3', :ref => "Me[one]", :configuration= => nil end it "should provide a method to add one or more resources" do @@ -376,7 +376,7 @@ describe Puppet::Node::Configuration, " when functioning as a resource container it "should be able to find resources by reference or by type/title tuple" do @config.add_resource @one - @config.resource("me", "you").should equal(@one) + @config.resource("me", "one").should equal(@one) end it "should have a mechanism for removing resources" do @@ -386,6 +386,32 @@ describe Puppet::Node::Configuration, " when functioning as a resource container @config.resource(@one.ref).should be_nil @config.vertex?(@one).should be_false end + + it "should have a method for creating aliases for resources" do + @config.add_resource @one + @config.alias(@one, "other") + @config.resource("me", "other").should equal(@one) + end + + # This test is the same as the previous, but the behaviour should be explicit. + it "should alias using the class name from the resource reference, not the resource class name" do + @config.add_resource @one + @config.alias(@one, "other") + @config.resource("me", "other").should equal(@one) + end + + it "should fail to add an alias if the aliased name already exists" do + @config.add_resource @one + proc { @config.alias @two, "one" }.should raise_error(ArgumentError) + end + + it "should remove resource aliases when the target resource is removed" do + @config.add_resource @one + @config.alias(@one, "other") + @one.expects :remove + @config.remove_resource(@one) + @config.resource("me", "other").should be_nil + end end module ApplyingConfigurations -- cgit