56
# Make sure our various metaparams work correctly. We're just checking
57
# here whether they correctly set up the callbacks and the direction of
59
def test_relationship_metaparams
60
out = {:require => false, :subscribe => false,
61
:notify => true, :before => true}
62
refreshers = [:subscribe, :notify]
63
[:require, :subscribe, :notify, :before].each do |param|
64
# Create three files to generate our events and three
65
# execs to receive them
69
files << Puppet::Type.newfile(
76
execs << Puppet::Type.newexec(
77
:title => "notifytest#{i}",
78
:path => "/usr/bin:/bin",
79
:command => "touch #{path}",
84
# Add our first relationship
86
files[0][param] = execs[0]
90
execs[0][param] = files[0]
94
check_relationship(sources, targets, out[param], refreshers.include?(param))
96
# Now add another relationship
98
files[0][param] = execs[1]
100
assert_equal(targets.collect { |t| [t.class.name, t.title]},
101
files[0][param], "Incorrect target list")
103
execs[0][param] = files[1]
105
assert_equal(sources.collect { |t| [t.class.name, t.title]},
106
execs[0][param], "Incorrect source list")
108
check_relationship(sources, targets, out[param], refreshers.include?(param))
110
Puppet::Type.allclear
114
def test_munge_relationship
115
file = Puppet::Type.newfile :path => tempfile(), :mode => 0755
118
execs << Puppet::Type.newexec(:title => "yay#{i}", :command => "/bin/echo yay")
121
# First try it with one object, specified as a reference and an array
123
[execs[0], [:exec, "yay0"], ["exec", "yay0"]].each do |target|
124
assert_nothing_raised do
125
result = file.send(:munge_relationship, :require, target)
128
assert_equal([[:exec, "yay0"]], result)
131
# Now try it with multiple objects
132
symbols = execs.collect { |e| [e.class.name, e.title] }
133
strings = execs.collect { |e| [e.class.name.to_s, e.title] }
134
[execs, symbols, strings].each do |target|
135
assert_nothing_raised do
136
result = file.send(:munge_relationship, :require, target)
139
assert_equal(symbols, result)
142
# Make sure we can mix it up, even though this shouldn't happen
143
assert_nothing_raised do
144
result = file.send(:munge_relationship, :require, [execs[0], [execs[1].class.name, execs[1].title]])
147
assert_equal([[:exec, "yay0"], [:exec, "yay1"]], result)
149
# Finally, make sure that new results get added to old. The only way
150
# to get rid of relationships is to delete the parameter.
151
file[:require] = execs[0]
153
assert_nothing_raised do
154
result = file.send(:munge_relationship, :require, [execs[1], execs[2]])
157
assert_equal(symbols, result)
160
56
def test_autorequire
161
57
# We know that execs autorequire their cwd, so we'll use that
164
file = Puppet::Type.newfile(:title => "myfile", :path => path,
60
file = Puppet::Type.type(:file).new(:title => "myfile", :path => path,
165
61
:ensure => :directory)
166
62
exec = Puppet::Type.newexec(:title => "myexec", :cwd => path,
167
63
:command => "/bin/echo")
65
catalog = mk_catalog(file, exec)
170
67
assert_nothing_raised do
171
68
reqs = exec.autorequire
173
70
assert_instance_of(Puppet::Relationship, reqs[0], "Did not return a relationship edge")
174
71
assert_equal(file, reqs[0].source, "Did not set the autorequire source correctly")
175
72
assert_equal(exec, reqs[0].target, "Did not set the autorequire target correctly")
177
# Now make sure that these relationships are added to the
74
# Now make sure that these relationships are added to the
178
75
# relationship graph
179
config = mk_catalog(file, exec)
180
config.apply do |trans|
181
assert(config.relationship_graph.edge?(file, exec), "autorequire edge was not created")
76
catalog.apply do |trans|
77
assert(catalog.relationship_graph.edge?(file, exec), "autorequire edge was not created")
186
# Test the first direction
187
file1 = Puppet::Type.newfile(:title => "one", :path => tempfile,
188
:ensure => :directory)
189
file2 = Puppet::Type.newfile(:title => "two", :path => tempfile,
190
:ensure => :directory)
192
file1[:require] = file2
193
assert(file1.requires?(file2), "requires? failed to catch :require relationship")
194
file1.delete(:require)
195
assert(! file1.requires?(file2), "did not delete relationship")
196
file1[:subscribe] = file2
197
assert(file1.requires?(file2), "requires? failed to catch :subscribe relationship")
198
file1.delete(:subscribe)
199
assert(! file1.requires?(file2), "did not delete relationship")
200
file2[:before] = file1
201
assert(file1.requires?(file2), "requires? failed to catch :before relationship")
202
file2.delete(:before)
203
assert(! file1.requires?(file2), "did not delete relationship")
204
file2[:notify] = file1
205
assert(file1.requires?(file2), "requires? failed to catch :notify relationship")
208
81
# Testing #411. It was a problem with builddepends.
209
82
def test_missing_deps
210
file = Puppet::Type.newfile :path => tempfile, :require => ["file", "/no/such/file"]
83
file = Puppet::Type.type(:file).new :path => tempfile, :require => Puppet::Resource::Reference.new("file", "/no/such/file")
212
85
assert_raise(Puppet::Error) do