---
 lib/puppet/event.rb |   45 ++++++++++++++++++++++++++++++++++++++
 spec/unit/event.rb  |   59 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 104 insertions(+), 0 deletions(-)
 create mode 100644 lib/puppet/event.rb
 create mode 100755 spec/unit/event.rb

diff --git a/lib/puppet/event.rb b/lib/puppet/event.rb
new file mode 100644
index 0000000..a0a367b
--- /dev/null
+++ b/lib/puppet/event.rb
@@ -0,0 +1,45 @@
+
+#require 'puppet'
+#require 'puppet/util/methodhelper'
+#require 'puppet/util/errors'
+
+# events are packets of information; they result in one or more (or none)
+# subscriptions getting triggered, and then they get cleared
+class Puppet::Event
+    include Puppet::Util::MethodHelper
+    include Puppet::Util::Errors
+
+    attr_reader  :name,          # e.g., 'file_changed'
+        :source,        # resource that triggered the event: e.g., File[/foo]
+        :timestamp,     # assumes time values are useful; e.g., running NTP
+        :node,          # host generating the event
+        :application,   # puppetd, puppetmasterd, puppetqd, an application, etc
+        :description,   # the actual message
+        :identifier,    # unique across all nodes
+        :level,         # like syslog level: notice, info, warning, error, etc
+        :parent_event   # optional
+
+    def initialize(name, source)
+        @name, @source = name, source
+        @timestamp = Time.now
+        # This is not sufficient, but is a start
+        @identifier =  "#...@node} #...@name} #...@timestamp}"
+    end
+
+    def to_s
+        "#...@timestamp} #...@node} #...@identifier} #[email protected]_s} 
#[email protected]_s}"
+    end
+
+    # There is a better way to do this
+    def info
+        Log('info', self.to_s())
+    end
+
+    def warn
+        Log('warn', self.to_s())
+    end
+
+    def err
+        Log('err', self.to_s())
+    end
+end
diff --git a/spec/unit/event.rb b/spec/unit/event.rb
new file mode 100755
index 0000000..993be5f
--- /dev/null
+++ b/spec/unit/event.rb
@@ -0,0 +1,59 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../spec_helper'
+
+require 'puppet/event'
+
+describe Puppet::Event do
+    Event = Puppet::Event
+
+    before do
+    #    @source = Event::Action.new('foo', 'create')
+        @sample = Event.new(@source, "bar")
+    end
+
+    it "should require a name and a source" do
+        lambda { Event.new }.should raise_error(ArgumentError)
+    end
+
+    it "should have a name getter" do
+        Event.new(:foo, "bar").name.should == :foo
+    end
+
+    it "should have a timestamp accessor and set its timestamp appropriately" 
do
+        time = stubs 'time'
+        Time.expects(:now).returns time
+        Event.new(:foo, "bar").timestamp.should equal(time)
+    end
+
+    #it "should raise an error if the source is not an Event::Action" do
+    #    lambda { Event.new(:foo, 'bar')}.should raise_error 
+    #end
+
+    it "should have a source accessor" do
+        Event.new(:foo, "bar").source.should == "bar"
+    end
+
+    it "should produce a string containing the event name and the source" do
+        Event.new(:event, :source).to_s.should =~ /source event/
+    end
+
+    it "should respond to to_json" do
+        @sample.should respond_to(:to_json)
+    end
+
+    it "should equal itself" do
+        time = stub 'time'
+        Time.expects(:now).returns time
+        e1 = Event.new(:foo, "bar")
+        e1.should equal(e1) 
+    end
+
+    it "should create a new event for a duplicate action" do
+        time = stub 'time'
+        Time.expects(:now).at_least_once.returns time
+        e1 = Event.new(:foo, "bar")
+        e2 = Event.new(:foo, "bar")
+        e1.should_not equal(e2) 
+    end
+end
-- 
1.6.3.3


--~--~---------~--~----~------------~-------~--~----~
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