diff options
| author | Luke Kanies <luke@madstop.com> | 2009-11-07 17:30:45 -0600 |
|---|---|---|
| committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
| commit | 977595bd712bfa25c176abb3983bc81df665ea7b (patch) | |
| tree | 1ae2ca7ed9c71ddbc8e7b378a6457282a8042ccd /spec | |
| parent | 5776fe4e33b5bb3399a2e72d76faeffb2bba1f4e (diff) | |
| download | puppet-977595bd712bfa25c176abb3983bc81df665ea7b.tar.gz puppet-977595bd712bfa25c176abb3983bc81df665ea7b.tar.xz puppet-977595bd712bfa25c176abb3983bc81df665ea7b.zip | |
Refactoring the Change/Event/Property interface
This gives all logging responsibility to the event, which
can now produce logs identical to those produced directly by
the property.
At this point, the events are entirely supersets of the logs.
Diffstat (limited to 'spec')
| -rwxr-xr-x | spec/unit/property.rb | 5 | ||||
| -rwxr-xr-x | spec/unit/transaction/change.rb | 17 | ||||
| -rwxr-xr-x | spec/unit/transaction/event.rb | 71 |
3 files changed, 78 insertions, 15 deletions
diff --git a/spec/unit/property.rb b/spec/unit/property.rb index 5bc29a61a..eba5c3d83 100755 --- a/spec/unit/property.rb +++ b/spec/unit/property.rb @@ -136,6 +136,11 @@ describe Puppet::Property do @instance.stubs(:should).returns "foo" @instance.event.desired_value.should == "foo" end + + it "should provide its path as the source description" do + @instance.stubs(:path).returns "/my/param" + @instance.event.source_description.should == "/my/param" + end end describe "when shadowing metaparameters" do diff --git a/spec/unit/transaction/change.rb b/spec/unit/transaction/change.rb index 4c22c8327..be1267bf6 100755 --- a/spec/unit/transaction/change.rb +++ b/spec/unit/transaction/change.rb @@ -77,6 +77,7 @@ describe Puppet::Transaction::Change do describe "and executing" do before do @event = Puppet::Transaction::Event.new(:myevent) + @event.stubs(:send_log) @change.stubs(:noop?).returns false @property.stubs(:event).returns @event @@ -91,9 +92,8 @@ describe Puppet::Transaction::Change do it "should log that it is in noop" do @property.expects(:is_to_s) @property.expects(:should_to_s) - @property.expects(:log).returns "my log" - @event.expects(:log=).with("my log") + @event.expects(:message=).with { |msg| msg.include?("should be") } @change.forward end @@ -132,14 +132,14 @@ describe Puppet::Transaction::Change do it "should log the change" do @property.expects(:sync).returns [:one] - @property.expects(:notice).returns "my log" + @event.expects(:send_log) @change.forward end - it "should set the event's log to the log" do - @property.expects(:notice).returns "my log" - @change.forward.log.should == "my log" + it "should set the event's message to the change log" do + @property.expects(:change_to_s).returns "my change" + @change.forward.message.should == "my change" end it "should set the event's status to 'success'" do @@ -150,7 +150,7 @@ describe Puppet::Transaction::Change do before { @property.expects(:sync).raises "an exception" } it "should catch the exception and log the err" do - @property.expects(:err) + @event.expects(:send_log) lambda { @change.forward }.should_not raise_error end @@ -159,8 +159,7 @@ describe Puppet::Transaction::Change do end it "should set the event log to a failure log" do - @property.expects(:err).returns "my failure" - @change.forward.log.should == "my failure" + @change.forward.message.should be_include("failed") end end diff --git a/spec/unit/transaction/event.rb b/spec/unit/transaction/event.rb index 7bdd0898e..07470b2b9 100755 --- a/spec/unit/transaction/event.rb +++ b/spec/unit/transaction/event.rb @@ -5,7 +5,7 @@ require File.dirname(__FILE__) + '/../../spec_helper' require 'puppet/transaction/event' describe Puppet::Transaction::Event do - [:log, :previous_value, :desired_value, :property, :resource, :name, :log, :node, :version, :file, :line, :tags].each do |attr| + [:previous_value, :desired_value, :property, :resource, :name, :message, :node, :version, :file, :line, :tags].each do |attr| it "should support #{attr}" do event = Puppet::Transaction::Event.new event.send(attr.to_s + "=", "foo") @@ -13,10 +13,18 @@ describe Puppet::Transaction::Event do end end - it "should produce the log when converted to a string" do + it "should always convert the property to a string" do + Puppet::Transaction::Event.new(:property => :foo).property.should == "foo" + end + + it "should always convert the resource to a string" do + Puppet::Transaction::Event.new(:resource => :foo).resource.should == "foo" + end + + it "should produce the message when converted to a string" do event = Puppet::Transaction::Event.new - event.expects(:log).returns "my log" - event.to_s.should == "my log" + event.expects(:message).returns "my message" + event.to_s.should == "my message" end it "should support 'status'" do @@ -34,9 +42,60 @@ describe Puppet::Transaction::Event do Puppet::Transaction::Event.ancestors.should include(Puppet::Util::Tagging) end - it "should be able to send logs" - it "should create a timestamp at its creation time" do Puppet::Transaction::Event.new.time.should be_instance_of(Time) end + + describe "when sending logs" do + before do + Puppet::Util::Log.stubs(:new) + end + + it "should set the level to 'notice' if the event status is 'success'" do + Puppet::Util::Log.expects(:new).with { |args| args[:level] == :notice } + Puppet::Transaction::Event.new(:status => "success").send_log + end + + it "should set the level to 'notice' if the event status is 'noop'" do + Puppet::Util::Log.expects(:new).with { |args| args[:level] == :notice } + Puppet::Transaction::Event.new(:status => "noop").send_log + end + + it "should set the level to 'err' if the event status is 'failure'" do + Puppet::Util::Log.expects(:new).with { |args| args[:level] == :err } + Puppet::Transaction::Event.new(:status => "failure").send_log + end + + it "should set the 'message' to the event log" do + Puppet::Util::Log.expects(:new).with { |args| args[:message] == "my message" } + Puppet::Transaction::Event.new(:message => "my message").send_log + end + + it "should set the tags to the event tags" do + Puppet::Util::Log.expects(:new).with { |args| args[:tags] == %w{one two} } + Puppet::Transaction::Event.new(:tags => %w{one two}).send_log + end + + [:file, :line, :version].each do |attr| + it "should pass the #{attr}" do + Puppet::Util::Log.expects(:new).with { |args| args[attr] == "my val" } + Puppet::Transaction::Event.new(attr => "my val").send_log + end + end + + it "should use the source description as the source if one is set" do + Puppet::Util::Log.expects(:new).with { |args| args[:source] == "/my/param" } + Puppet::Transaction::Event.new(:source_description => "/my/param", :resource => "Foo[bar]", :property => "foo").send_log + end + + it "should use the property as the source if one is available and no source description is set" do + Puppet::Util::Log.expects(:new).with { |args| args[:source] == "foo" } + Puppet::Transaction::Event.new(:resource => "Foo[bar]", :property => "foo").send_log + end + + it "should use the property as the source if one is available and no property or source description is set" do + Puppet::Util::Log.expects(:new).with { |args| args[:source] == "Foo[bar]" } + Puppet::Transaction::Event.new(:resource => "Foo[bar]").send_log + end + end end |
