File tree Expand file tree Collapse file tree 6 files changed +23
-3
lines changed
lib/puppet/parser/functions Expand file tree Collapse file tree 6 files changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ module Puppet::Parser::Functions
30
30
end
31
31
32
32
args . each do |arg |
33
- unless arg . is_a? ( String )
33
+ unless arg . is_a? ( String ) || arg . nil?
34
34
raise Puppet ::ParseError , ( "#{ arg . inspect } is not a string. It looks to be a #{ arg . class } " )
35
35
end
36
36
end
Original file line number Diff line number Diff line change 95
95
expect ( r . stdout ) . to match ( /Notice: output correct/ )
96
96
end
97
97
end
98
+ it 'is_strings undef' do
99
+ pp = <<-EOS
100
+ $a = undef
101
+ $o = is_string($a)
102
+ notice(inline_template('is_string is <%= @o.inspect %>'))
103
+ EOS
104
+
105
+ apply_manifest ( pp , :catch_failures => true ) do |r |
106
+ expect ( r . stdout ) . to match ( /is_string is true/ )
107
+ end
108
+ end
98
109
end
99
110
describe 'failure' do
100
111
it 'handles improper argument counts'
Original file line number Diff line number Diff line change 20
20
21
21
apply_manifest ( pp , :catch_failures => true )
22
22
end
23
+ it 'validates undef' do
24
+ pp = <<-EOS
25
+ validate_string(undef)
26
+ EOS
27
+
28
+ apply_manifest ( pp , :catch_failures => true )
29
+ end
23
30
it 'validates a non-string' do
24
31
{
25
32
%{validate_string({ 'a' => 'hash' })} => "Hash" ,
Original file line number Diff line number Diff line change 6
6
[
7
7
'' ,
8
8
'one' ,
9
+ nil ,
9
10
] . each do |value |
10
11
describe value . inspect do
11
12
let ( :params ) { { value : value } }
23
24
] . each do |value |
24
25
describe value . inspect do
25
26
let ( :params ) { { value : value } }
26
- it { is_expected . to compile . and_raise_error ( /parameter 'value' expects a Stdlib::Compat::String = String/ ) }
27
+ it { is_expected . to compile . and_raise_error ( /parameter 'value' expects a String/ ) }
27
28
end
28
29
end
29
30
end
Original file line number Diff line number Diff line change 18
18
19
19
describe 'valid inputs' do
20
20
it { is_expected . to run . with_params ( '' ) }
21
+ it { is_expected . to run . with_params ( nil ) }
21
22
it { is_expected . to run . with_params ( 'one' ) }
22
23
it { is_expected . to run . with_params ( 'one' , 'two' ) }
23
24
end
Original file line number Diff line number Diff line change 1
1
# Emulate the is_string and validate_string functions
2
- type Stdlib::Compat::String = String
2
+ type Stdlib::Compat::String = Optional[ String]
You can’t perform that action at this time.
0 commit comments