summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Berry <paul@puppetlabs.com>2011-01-07 14:43:57 -0800
committerPaul Berry <paul@puppetlabs.com>2011-01-07 14:44:43 -0800
commitc57a677638db14a4d38144cc18e2055fedca8f5e (patch)
treebb8f339cd138c9435dff4528431fbd927133f931
parent814f56fdb3d360531bc2a2fc85ac71127a4c779d (diff)
downloadpuppet-c57a677638db14a4d38144cc18e2055fedca8f5e.tar.gz
puppet-c57a677638db14a4d38144cc18e2055fedca8f5e.tar.xz
puppet-c57a677638db14a4d38144cc18e2055fedca8f5e.zip
Maint: test partial resource failure
Added a resource harness test to verify that the correct events are generated if there is a failure while synchronizing a resource. Paired-with: Jesse Wolfe <jesse@puppetlabs.com>
-rwxr-xr-xspec/unit/transaction/resource_harness_spec.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/spec/unit/transaction/resource_harness_spec.rb b/spec/unit/transaction/resource_harness_spec.rb
index 65c148a93..ca35740f5 100755
--- a/spec/unit/transaction/resource_harness_spec.rb
+++ b/spec/unit/transaction/resource_harness_spec.rb
@@ -64,6 +64,64 @@ describe Puppet::Transaction::ResourceHarness do
end
end
+ describe "when an error occurs" do
+ before :each do
+ # Create a temporary anonymous class to act as a provider
+ stubProvider = Class.new(Puppet::Type)
+ stubProvider.instance_eval do
+ initvars
+
+ newparam(:name) do
+ desc "The name var"
+ isnamevar
+ end
+
+ newproperty(:foo) do
+ desc "A property that can be changed successfully"
+ def sync
+ end
+
+ def retrieve
+ :absent
+ end
+
+ def insync?(reference_value)
+ false
+ end
+ end
+
+ newproperty(:bar) do
+ desc "A property that raises an exception when you try to change it"
+ def sync
+ raise ZeroDivisionError.new('bar')
+ end
+
+ def retrieve
+ :absent
+ end
+
+ def insync?(reference_value)
+ false
+ end
+ end
+ end
+
+ resource = stubProvider.new :name => 'name', :foo => 1, :bar => 2
+ resource.expects(:err).never
+ @status = @harness.evaluate(resource)
+ end
+
+ it "should record previous successful events" do
+ @status.events[0].property.should == 'foo'
+ @status.events[0].status.should == 'success'
+ end
+
+ it "should record a failure event" do
+ @status.events[1].property.should == 'bar'
+ @status.events[1].status.should == 'failure'
+ end
+ end
+
describe "when applying changes" do
[false, true].each do |noop_mode|; describe (noop_mode ? "in noop mode" : "in normal mode") do
[nil, '750'].each do |machine_state|; describe (machine_state ? "with a file initially present" : "with no file initially present") do