File tree Expand file tree Collapse file tree
lib/puppet/parser/functions Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4848 title = nil
4949 end
5050
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 |
5358 matches = params . map do |key , value |
5459 # eql? avoids bugs caused by monkeypatching in puppet
5560 resource_is_undef = resource [ key ] . eql? ( :undef ) || resource [ key ] . nil?
5661 value_is_undef = value . eql? ( :undef ) || value . nil?
5762 ( resource_is_undef && value_is_undef ) || ( resource [ key ] == value )
5863 end
5964 ret = params . empty? || !matches . include? ( false )
65+
66+ break if ret
6067 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+
6271 ret
6372end
Original file line number Diff line number Diff line change 6363
6464 describe 'when passed a defined type' do
6565 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
6784 end
6885
6986 it { is_expected . to run . with_params ( 'Test::Deftype[foo]' , { } ) . and_return ( true ) }
7087 it { is_expected . to run . with_params ( 'Test::Deftype[bar]' , { } ) . and_return ( false ) }
7188 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+ }
7395 end
7496
7597 describe 'when passed a class' do
You can’t perform that action at this time.
0 commit comments