1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
if __FILE__ == $0
$:.unshift '..'
$:.unshift '../../lib'
$puppetbase = "../../../../language/trunk"
end
require 'puppet'
require 'puppettest'
require 'test/unit'
# $Id$
class TestEvents < Test::Unit::TestCase
include TestPuppet
def teardown
super
Puppet::Event::Subscription.clear
end
def test_simplesubscribe
name = tempfile()
file = Puppet.type(:file).create(
:name => name,
:ensure => "file"
)
exec = Puppet.type(:exec).create(
:name => "echo true",
:path => "/usr/bin:/bin",
:refreshonly => true,
:subscribe => [[file.class.name, file.name]]
)
comp = newcomp("eventtesting", file, exec)
trans = assert_events([:file_created], comp)
assert_equal(1, trans.triggered?(exec, :refresh))
end
def test_simplerequire
name = tempfile()
file = Puppet.type(:file).create(
:name => name,
:ensure => "file"
)
exec = Puppet.type(:exec).create(
:name => "echo true",
:path => "/usr/bin:/bin",
:refreshonly => true,
:require => [[file.class.name, file.name]]
)
comp = Puppet.type(:component).create(
:name => "eventtesting"
)
comp.push exec
trans = comp.evaluate
events = nil
assert_nothing_raised {
events = trans.evaluate
}
assert_equal(1, events.length)
assert_equal(0, trans.triggered?(exec, :refresh))
end
def test_ladderrequire
comps = {}
objects = {}
fname = tempfile()
[:a, :b].each { |l|
case l
when :a
name = tempfile() + l.to_s
objects[l] = Puppet.type(:file).create(
:name => name,
:ensure => "file"
)
@@tmpfiles << name
when :b
objects[l] = Puppet.type(:exec).create(
:name => "touch %s" % fname,
:path => "/usr/bin:/bin",
:refreshonly => true
)
@@tmpfiles << fname
end
comps[l] = Puppet.type(:component).create(
:name => "eventtesting%s" % l
)
comps[l].push objects[l]
}
comps[:b][:subscribe] = [[comps[:a].class.name, comps[:a].name]]
Puppet::Type.finalize
trans = comps[:a].evaluate
events = nil
assert_nothing_raised {
events = trans.evaluate
}
assert(FileTest.exists?(fname))
#assert_equal(events.length, trans.triggered?(objects[:b], :refresh))
end
end
|