3 require File.dirname(__FILE__) + '/../lib/puppettest'
9 class TestEvents < Test::Unit::TestCase
12 def test_simplesubscribe
14 file = Puppet.type(:file).create(
18 exec = Puppet.type(:exec).create(
20 :path => "/usr/bin:/bin",
22 :subscribe => [[file.class.name, file.name]]
25 comp = mk_catalog("eventtesting", file, exec)
27 trans = assert_events([:file_created, :triggered], comp)
29 assert_equal(1, trans.triggered?(exec, :refresh))
32 def test_simplerequire
34 file = Puppet.type(:file).create(
38 exec = Puppet.type(:exec).create(
40 :path => "/usr/bin:/bin",
42 :require => [[file.class.name, file.name]]
47 config.add_resource file
48 config.add_resource exec
51 assert_equal(1, trans.events.length)
53 assert_equal(0, trans.triggered?(exec, :refresh))
56 def test_multiplerefreshes
60 files << Puppet.type(:file).create(
67 exec = Puppet.type(:exec).create(
68 :name => "touch %s" % fname,
69 :path => "/usr/bin:/bin",
73 exec[:subscribe] = files.collect { |f|
77 comp = mk_catalog(exec, *files)
80 assert(FileTest.exists?(fname), "Exec file did not get created")
83 # Make sure refreshing happens mid-transaction, rather than at the end.
84 def test_refreshordering
87 exec1 = Puppet.type(:exec).create(
89 :name => "echo one >> %s" % file,
90 :path => "/usr/bin:/bin"
93 exec2 = Puppet.type(:exec).create(
95 :name => "echo two >> %s" % file,
96 :path => "/usr/bin:/bin",
101 exec3 = Puppet.type(:exec).create(
103 :name => "echo three >> %s" % file,
104 :path => "/usr/bin:/bin",
107 execs = [exec1, exec2, exec3]
109 config = mk_catalog(exec1,exec2,exec3)
111 trans = Puppet::Transaction.new(config)
112 execs.each do |e| assert(config.vertex?(e), "%s is not in graph" % e.title) end
114 execs.each do |e| assert(config.vertex?(e), "%s is not in relgraph" % e.title) end
115 reverse = trans.relationship_graph.reversal
116 execs.each do |e| assert(reverse.vertex?(e), "%s is not in reversed graph" % e.title) end
120 assert(FileTest.exists?(file), "File does not exist")
122 assert_equal("one\ntwo\nthree\n", File.read(file))