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 <[email protected]>
Signed-off-by: Paul Berry <[email protected]>
---
 spec/unit/transaction/resource_harness_spec.rb |   58 ++++++++++++++++++++++++
 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 65c148a..ca35740 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
-- 
1.7.2

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to