Skip to content

Commit e54b31e

Browse files
Merge pull request #22 from seanmil/tolerate_nil_autorequires
Handle nil autorequire results
2 parents 0463408 + 56d6b94 commit e54b31e

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

lib/rspec-puppet/matchers/create_generic.rb

+2
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ def relationship_refs(resource, type, visited = Set.new)
313313
if resource.resource_type.respond_to?(func)
314314
resource.resource_type.send(func) do |t, b|
315315
Array(resource.to_ral.instance_eval(&b)).each do |dep|
316+
next if dep.nil?
317+
316318
res = "#{t.to_s.capitalize}[#{dep}]"
317319
if r = relationship_refs(res, type, visited)
318320
results << res

spec/classes/relationships__type_with_auto.rb

-17
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require 'spec_helper'
2+
3+
describe 'relationships::type_with_auto', :if => Puppet::Util::Package.versioncmp(Puppet.version, '4.0.0') >= 0 do
4+
it { is_expected.to compile.with_all_deps }
5+
it do
6+
is_expected.to contain_type_with_all_auto('test')
7+
.that_comes_before('Notify[test/before]')
8+
.that_notifies('Notify[test/notify]')
9+
.that_requires('Notify[test/require]')
10+
.that_subscribes_to('Notify[test/subscribe]')
11+
end
12+
13+
it { is_expected.to contain_notify('test/before').that_requires('Type_with_all_auto[test]') }
14+
it { is_expected.to contain_notify('test/notify').that_subscribes_to('Type_with_all_auto[test]') }
15+
it { is_expected.to contain_notify('test/require').that_comes_before('Type_with_all_auto[test]') }
16+
it { is_expected.to contain_notify('test/subscribe').that_notifies('Type_with_all_auto[test]') }
17+
end
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Puppet::Type.newtype(:type_with_all_auto) do
22
ensurable
33
newparam(:name, :namevar => true)
4-
autobefore(:file) { [File.join(self[:name], 'before')] }
5-
autonotify(:file) { [File.join(self[:name], 'notify')] }
6-
autorequire(:file) { [File.join(self[:name], 'require')] }
7-
autosubscribe(:file) { [File.join(self[:name], 'subscribe')] }
4+
autobefore(:notify) { ["#{self[:name]}/before", nil] }
5+
autonotify(:notify) { ["#{self[:name]}/notify", nil] }
6+
autorequire(:notify) { ["#{self[:name]}/require", nil] }
7+
autosubscribe(:notify) { ["#{self[:name]}/subscribe", nil] }
88
end
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# This class is here to test type_with_all_auto which has alll auto* relations
22
class relationships::type_with_auto {
3-
type_with_all_auto { '/tmp':
3+
type_with_all_auto { 'test':
44
}
55

6-
file { ['/tmp/before', '/tmp/notify', '/tmp/require', '/tmp/subscribe']:
7-
ensure => file,
8-
}
6+
notify { ['test/before', 'test/notify', 'test/require', 'test/subscribe']: }
97
}

0 commit comments

Comments
 (0)