Skip to content

Commit

Permalink
fix voxpupuli#238 cannot pass function via variable
Browse files Browse the repository at this point in the history
  • Loading branch information
lbetz authored and n00by committed Apr 26, 2018
1 parent ac27ec2 commit f79ac45
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
9 changes: 8 additions & 1 deletion lib/puppet_x/icinga2/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,14 @@ def self.attribute_types(attr)
def self.parse(row)
result = ''

if row =~ /^(.+)\s([\+-]|\*|\/|==|!=|&&|\|{2}|in)\s(.+)$/
# scan function
if row =~ /^\{{2}(.+)\}{2}$/
result += "{{%s}}" % [ $1 ]
# scan expression + function (function should contain expressions, but we donno parse it)
elsif row =~ /^(.+)\s([\+-]|\*|\/|==|!=|&&|\|{2}|in)\s\{{2}(.+)\}{2}$/
result += "%s %s {{%s}}" % [ parse($1), $2, $3 ]
# scan expression
elsif row =~ /^(.+)\s([\+-]|\*|\/|==|!=|&&|\|{2}|in)\s(.+)$/
result += "%s %s %s" % [ parse($1), $2, parse($3) ]
else
if row =~ /^(.+)\((.*)$/
Expand Down
44 changes: 38 additions & 6 deletions spec/defines/object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,27 @@
end


context "#{os} with attrs => { foo => {{ unparsed string }} }" do
let(:params) { {:attrs => { 'foo' => '{{ unparsed string }}' }, :object_type => 'foo', :target => '/bar/baz', :order => '10'} }
context "#{os} with attrs => { foo => {{ 0.8 * macro($bar$) }} }" do
let(:params) { {:attrs => { 'foo' => '{{ 0.8 * macro($bar$) }}' }, :object_type => 'foo', :target => '/bar/baz', :order => '10'} }

it { is_expected.to contain_concat__fragment('bar')
.with_content(/foo = \{{2} unparsed string \}{2}\n/) }
.with_content(/foo = \{{2} 0.8 \* macro\(\$bar\$\) \}{2}/) }
end


context "#{os} with attrs => { foo => 6 + {{ 0.8 * macro($bar$) }} }" do
let(:params) { {:attrs => { 'foo' => '6 + {{ 0.8 * macro($bar$) }}' }, :object_type => 'foo', :target => '/bar/baz', :order => '10'} }

it { is_expected.to contain_concat__fragment('bar')
.with_content(/foo = 6 \+ \{{2} 0.8 \* macro\(\$bar\$\) \}{2}/) }
end


context "#{os} with attrs => { foo => {{ 0.8 * macro($bar$) }} / 2 }" do
let(:params) { {:attrs => { 'foo' => '{{ 0.8 * macro($bar$) }} / 2' }, :object_type => 'foo', :target => '/bar/baz', :order => '10'} }

it { is_expected.to contain_concat__fragment('bar')
.with_content(/foo = \{{2} 0.8 \* macro\(\$bar\$\) \}{2} \/ 2/) }
end
end
end
Expand Down Expand Up @@ -481,10 +497,26 @@
end


context "Windows 2012 R2 with attrs => { foo => {{ unparsed string }} }" do
let(:params) { {:attrs => { 'foo' => '{{ unparsed string }}' }, :object_type => 'foo', :target => 'C:/bar/baz', :order => '10'} }
context "Windows 2012 R2 with attrs => { foo => {{ 0.8 * macro($bar$) }} }" do
let(:params) { {:attrs => { 'foo' => '{{ 0.8 * macro($bar$) }}' }, :object_type => 'foo', :target => 'C:/bar/baz', :order => '10'} }

it { is_expected.to contain_concat__fragment('bar')
.with_content(/foo = \{{2} 0.8 \* macro\(\$bar\$\) \}{2}/) }
end


context "Windows 2012 R2 with attrs => { foo => 6 + {{ 0.8 * macro($bar$) }} }" do
let(:params) { {:attrs => { 'foo' => '6 + {{ 0.8 * macro($bar$) }}' }, :object_type => 'foo', :target => 'C:/bar/baz', :order => '10'} }

it { is_expected.to contain_concat__fragment('bar')
.with_content(/foo = 6 \+ \{{2} 0.8 \* macro\(\$bar\$\) \}{2}/) }
end


context "Windows 2012 R2 with attrs => { foo => {{ 0.8 * macro($bar$) }} / 2 }" do
let(:params) { {:attrs => { 'foo' => '{{ 0.8 * macro($bar$) }} / 2' }, :object_type => 'foo', :target => 'C:/bar/baz', :order => '10'} }

it { is_expected.to contain_concat__fragment('bar')
.with_content(/foo = \{{2} unparsed string \}{2}\r\n/) }
.with_content(/foo = \{{2} 0.8 \* macro\(\$bar\$\) \}{2} \/ 2/) }
end
end

0 comments on commit f79ac45

Please sign in to comment.