From 98db2da4e9b35f6260bf07c641550b380b603baa Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Thu, 30 Dec 2010 11:01:23 -0800 Subject: (#5715) Removed unnecessary attributes from YAML of Puppet::Transaction::Event. The removed attributes are file, line, resource, tags, source_description, and default_log_level. These attributes were all redundant with those in Puppet::Resource::Status. --- lib/puppet/transaction/event.rb | 5 +++++ spec/unit/transaction/event_spec.rb | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/lib/puppet/transaction/event.rb b/lib/puppet/transaction/event.rb index b9fa5c38b..64980f1d9 100644 --- a/lib/puppet/transaction/event.rb +++ b/lib/puppet/transaction/event.rb @@ -8,6 +8,7 @@ class Puppet::Transaction::Event include Puppet::Util::Logging ATTRIBUTES = [:name, :resource, :property, :previous_value, :desired_value, :historical_value, :status, :message, :file, :line, :source_description, :audited] + YAML_ATTRIBUTES = %w{@audited @property @previous_value @desired_value @historical_value @message @name @status @time} attr_accessor *ATTRIBUTES attr_writer :tags attr_accessor :time @@ -47,6 +48,10 @@ class Puppet::Transaction::Event message end + def to_yaml_properties + (YAML_ATTRIBUTES & instance_variables).sort + end + private # If it's a failure, use 'err', else use either the resource's log level (if available) diff --git a/spec/unit/transaction/event_spec.rb b/spec/unit/transaction/event_spec.rb index 2776be8d7..6ed14722b 100755 --- a/spec/unit/transaction/event_spec.rb +++ b/spec/unit/transaction/event_spec.rb @@ -111,4 +111,17 @@ describe Puppet::Transaction::Event do Puppet::Transaction::Event.new(:resource => "Foo[bar]").send_log end end + + describe "When converting to YAML" do + it "should include only documented attributes" do + resource = Puppet::Type.type(:file).new(:title => "/tmp/foo") + event = Puppet::Transaction::Event.new(:source_description => "/my/param", :resource => resource, + :file => "/foo.rb", :line => 27, :tags => %w{one two}, + :desired_value => 7, :historical_value => 'Brazil', + :message => "Help I'm trapped in a spec test", + :name => :mode_changed, :previous_value => 6, :property => :mode, + :status => 'success') + event.to_yaml_properties.should == Puppet::Transaction::Event::YAML_ATTRIBUTES.sort + end + end end -- cgit