diff options
Diffstat (limited to 'spec/unit/node/catalog.rb')
| -rwxr-xr-x | spec/unit/node/catalog.rb | 57 |
1 files changed, 40 insertions, 17 deletions
diff --git a/spec/unit/node/catalog.rb b/spec/unit/node/catalog.rb index 3833890f7..6f246f6b3 100755 --- a/spec/unit/node/catalog.rb +++ b/spec/unit/node/catalog.rb @@ -308,8 +308,6 @@ describe Puppet::Node::Catalog, " when converting to a RAL catalog" do newconfig = nil - Puppet::Type.allclear - proc { @catalog = config.to_ral }.should_not raise_error @catalog.resource("Test[changer2]").should equal(resource) end @@ -323,9 +321,9 @@ end describe Puppet::Node::Catalog, " when functioning as a resource container" do before do @catalog = Puppet::Node::Catalog.new("host") - @one = stub 'resource1', :ref => "Me[one]", :catalog= => nil - @two = stub 'resource2', :ref => "Me[two]", :catalog= => nil - @dupe = stub 'resource3', :ref => "Me[one]", :catalog= => nil + @one = stub 'resource1', :ref => "Me[one]", :catalog= => nil, :title => "one", :[] => "one" + @two = stub 'resource2', :ref => "Me[two]", :catalog= => nil, :title => "two", :[] => "two" + @dupe = stub 'resource3', :ref => "Me[one]", :catalog= => nil, :title => "one", :[] => "one" end it "should provide a method to add one or more resources" do @@ -437,6 +435,28 @@ describe Puppet::Node::Catalog, " when functioning as a resource container" do @catalog.resource("me", "other").should equal(@one) end + it "should ignore conflicting aliases that point to the aliased resource" do + @catalog.alias(@one, "other") + lambda { @catalog.alias(@one, "other") }.should_not raise_error + end + + it "should create aliases for resources isomorphic resources whose names do not match their titles" do + resource = Puppet::Type::File.create(:title => "testing", :path => "/something") + + @catalog.add_resource(resource) + + @catalog.resource(:file, "/something").should equal(resource) + end + + it "should not create aliases for resources non-isomorphic resources whose names do not match their titles" do + resource = Puppet::Type.type(:exec).create(:title => "testing", :command => "echo", :path => %w{/bin /usr/bin /usr/local/bin}) + + @catalog.add_resource(resource) + + # Yay, I've already got a 'should' method + @catalog.resource(:exec, "echo").object_id.should == nil.object_id + 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 @catalog.add_resource @one @@ -444,11 +464,16 @@ describe Puppet::Node::Catalog, " when functioning as a resource container" do @catalog.resource("me", "other").should equal(@one) end - it "should fail to add an alias if the aliased name already exists" do + it "should fail to add an alias if the aliased name already exists as a resource" do @catalog.add_resource @one proc { @catalog.alias @two, "one" }.should raise_error(ArgumentError) end + it "should fail to add an alias if the aliased name already exists as an alias" do + @catalog.alias(@one, "yayness") + proc { @catalog.alias @two, "yayness" }.should raise_error(ArgumentError) + end + it "should remove resource aliases when the target resource is removed" do @catalog.add_resource @one @catalog.alias(@one, "other") @@ -457,8 +482,10 @@ describe Puppet::Node::Catalog, " when functioning as a resource container" do @catalog.resource("me", "other").should be_nil end - after do - Puppet::Type.allclear + it "should return aliased resources when asked for the resource by the alias" do + @catalog.add_resource @one + @catalog.alias(@one, "other") + @catalog.resource("Me[other]").should equal(@one) end end @@ -645,14 +672,14 @@ describe Puppet::Node::Catalog, " when creating a relationship graph" do end it "should look up resources in the relationship graph if not found in the main catalog" do - five = stub 'five', :ref => "File[five]", :catalog= => nil + five = stub 'five', :ref => "File[five]", :catalog= => nil, :title => "five", :[] => "five" @relationships.add_resource five @catalog.resource(five.ref).should equal(five) end it "should provide a method to create additional resources that also registers the resource" do args = {:name => "/yay", :ensure => :file} - resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog + resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog, :title => "/yay", :[] => "/yay" Puppet::Type.type(:file).expects(:create).with(args).returns(resource) @catalog.create_resource :file, args @catalog.resource("File[/yay]").should equal(resource) @@ -660,7 +687,7 @@ describe Puppet::Node::Catalog, " when creating a relationship graph" do it "should provide a mechanism for creating implicit resources" do args = {:name => "/yay", :ensure => :file} - resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog + resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog, :title => "/yay", :[] => "/yay" Puppet::Type.type(:file).expects(:create).with(args).returns(resource) resource.expects(:implicit=).with(true) @catalog.create_implicit_resource :file, args @@ -669,7 +696,7 @@ describe Puppet::Node::Catalog, " when creating a relationship graph" do it "should add implicit resources to the relationship graph if there is one" do args = {:name => "/yay", :ensure => :file} - resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog + resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog, :title => "/yay", :[] => "/yay" resource.expects(:implicit=).with(true) Puppet::Type.type(:file).expects(:create).with(args).returns(resource) # build the graph @@ -681,7 +708,7 @@ describe Puppet::Node::Catalog, " when creating a relationship graph" do it "should remove resources created mid-transaction" do args = {:name => "/yay", :ensure => :file} - resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog + resource = stub 'file', :ref => "File[/yay]", :catalog= => @catalog, :title => "/yay", :[] => "/yay" @transaction = mock 'transaction' Puppet::Transaction.stubs(:new).returns(@transaction) @transaction.stubs(:evaluate) @@ -700,10 +727,6 @@ describe Puppet::Node::Catalog, " when creating a relationship graph" do @catalog.remove_resource(@one) @catalog.relationship_graph.vertex?(@one).should be_false end - - after do - Puppet::Type.allclear - end end describe Puppet::Node::Catalog, " when writing dot files" do |
