File tree Expand file tree Collapse file tree 2 files changed +36
-5
lines changed
lib/puppet/parser/functions Expand file tree Collapse file tree 2 files changed +36
-5
lines changed Original file line number Diff line number Diff line change 48
48
title = nil
49
49
end
50
50
51
- resource = findresource ( type , title )
52
- if resource
51
+ resources = if title . empty?
52
+ catalog . resources . select { |r | r . type == type }
53
+ else
54
+ [ findresource ( type , title ) ]
55
+ end
56
+
57
+ resources . compact . each do |resource |
53
58
matches = params . map do |key , value |
54
59
# eql? avoids bugs caused by monkeypatching in puppet
55
60
resource_is_undef = resource [ key ] . eql? ( :undef ) || resource [ key ] . nil?
56
61
value_is_undef = value . eql? ( :undef ) || value . nil?
57
62
( resource_is_undef && value_is_undef ) || ( resource [ key ] == value )
58
63
end
59
64
ret = params . empty? || !matches . include? ( false )
65
+
66
+ break if ret
60
67
end
61
- Puppet . debug ( "Resource #{ reference } was not determined to be defined" )
68
+
69
+ Puppet . debug ( "Resource #{ reference } was not determined to be defined" ) unless ret
70
+
62
71
ret
63
72
end
Original file line number Diff line number Diff line change 63
63
64
64
describe 'when passed a defined type' do
65
65
let :pre_condition do
66
- 'define test::deftype() { } test::deftype { "foo": }'
66
+ <<-PRECOND
67
+ define test::deftype(
68
+ Optional $port = undef
69
+ ) { }
70
+
71
+ test::deftype { "foo": }
72
+ test::deftype { "baz": port => 100 }
73
+ test::deftype { "adv": port => 200 }
74
+ test::deftype { "adv2": port => 200 }
75
+
76
+ # Unsure how to stub this out below properly
77
+ if defined_with_params(Test::Deftype, { 'port' => 200 }) {
78
+ notify { 'Duplicate found somewhere': }
79
+ }
80
+ if defined_with_params(Test::Deftype, { 'port' => 'nope' }) {
81
+ notify { 'Should not find me': }
82
+ }
83
+ PRECOND
67
84
end
68
85
69
86
it { is_expected . to run . with_params ( 'Test::Deftype[foo]' , { } ) . and_return ( true ) }
70
87
it { is_expected . to run . with_params ( 'Test::Deftype[bar]' , { } ) . and_return ( false ) }
71
88
it { is_expected . to run . with_params ( Puppet ::Resource . new ( 'Test::Deftype[foo]' ) , { } ) . and_return ( true ) }
72
- it { is_expected . to run . with_params ( Puppet ::Resource . new ( 'Test::Deftype[bar]' ) , { } ) . and_return ( false ) }
89
+ it {
90
+ is_expected . to run . with_params ( Puppet ::Resource . new ( 'Test::Deftype[bar]' ) , { } ) . and_return ( false )
91
+
92
+ expect ( catalogue . resource ( 'Notify[Duplicate found somewhere]' ) ) . not_to be_nil
93
+ expect ( catalogue . resource ( 'Notify[Should not find me]' ) ) . to be_nil
94
+ }
73
95
end
74
96
75
97
describe 'when passed a class' do
You can’t perform that action at this time.
0 commit comments