summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorRein Henrichs <reinh@reinh.com>2009-11-11 11:17:13 -0800
committerJames Turnbull <james@lovedthanlost.net>2009-11-13 08:32:19 +1100
commit53f40bd336d709e717edb621a9d68dde9a4d5bce (patch)
treed119798f1bd34b49ea58aa8436ae20e9286a2577 /spec
parent3fdc8effbe25c9653d8bc86f2d4847984d4cb6f3 (diff)
downloadpuppet-53f40bd336d709e717edb621a9d68dde9a4d5bce.tar.gz
puppet-53f40bd336d709e717edb621a9d68dde9a4d5bce.tar.xz
puppet-53f40bd336d709e717edb621a9d68dde9a4d5bce.zip
Fix #2681 Incorrectly duplicating resources
Ensure that resources whose refs are included in the catalog are skipped to avoid duplication. * Refactor to avoid early bailout on resources that cannot be ensured absent. * Remove check for managed? in generate Checking if a resource is managed is unnecessary when checking for its inclusion in the catalog. * Add test coverage for Puppet::Type::Resources#generate
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/type/resources.rb65
1 files changed, 65 insertions, 0 deletions
diff --git a/spec/unit/type/resources.rb b/spec/unit/type/resources.rb
index 147f21db4..a3faededa 100644
--- a/spec/unit/type/resources.rb
+++ b/spec/unit/type/resources.rb
@@ -21,4 +21,69 @@ describe resources do
resources.new(:name => "file").resource_type.should == Puppet::Type.type(:file)
end
end
+
+ describe "#generate" do
+ before do
+ @host1 = Puppet::Type.type(:host).new(:name => 'localhost', :ip => '127.0.0.1')
+ @catalog = Puppet::Resource::Catalog.new
+ @context = Puppet::Transaction.new(@catalog)
+ end
+
+ describe "when dealing with non-purging resources" do
+ before do
+ @resources = Puppet::Type.type(:resources).new(:name => 'host')
+ end
+
+ it "should not generate any resource" do
+ @resources.generate.should be_empty
+ end
+ end
+
+ describe "when the catalog contains a purging resource" do
+ before do
+ @resources = Puppet::Type.type(:resources).new(:name => 'host', :purge => true)
+ @purgeable_resource = Puppet::Type.type(:host).new(:name => 'localhost', :ip => '127.0.0.1')
+ @catalog.add_resource @resources
+ end
+
+ it "should not generate a duplicate of that resource" do
+ Puppet::Type.type(:host).stubs(:instances).returns [@host1]
+ @catalog.add_resource @host1
+ @resources.generate.collect { |r| r.ref }.should_not include(@host1.ref)
+ end
+
+
+ describe "when generating a purgeable resource" do
+ it "should be included in the generated resources" do
+ Puppet::Type.type(:host).stubs(:instances).returns [@purgeable_resource]
+ @resources.generate.collect { |r| r.ref }.should include(@purgeable_resource.ref)
+ end
+ end
+
+ describe "when the instance's do not have an ensure property" do
+ it "should not be included in the generated resources" do
+ @no_ensure_resource = Puppet::Type.type(:exec).new(:name => '/usr/bin/env echo')
+ Puppet::Type.type(:host).stubs(:instances).returns [@no_ensure_resource]
+ @resources.generate.collect { |r| r.ref }.should_not include(@no_ensure_resource.ref)
+ end
+ end
+
+ describe "when the instance's ensure property does not accept absent" do
+ it "should not be included in the generated resources" do
+ @no_absent_resource = Puppet::Type.type(:service).new(:name => 'foobar')
+ Puppet::Type.type(:host).stubs(:instances).returns [@no_absent_resource]
+ @resources.generate.collect { |r| r.ref }.should_not include(@no_absent_resource.ref)
+ end
+ end
+
+ describe "when checking the instance fails" do
+ it "should not be included in the generated resources" do
+ @purgeable_resource = Puppet::Type.type(:host).new(:name => 'foobar')
+ Puppet::Type.type(:host).stubs(:instances).returns [@purgeable_resource]
+ @resources.expects(:check).with(@purgeable_resource).returns(false)
+ @resources.generate.collect { |r| r.ref }.should_not include(@purgeable_resource.ref)
+ end
+ end
+ end
+ end
end