forked from voxpupuli/puppet-rundeck
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request voxpupuli#44 from puppet-community/fix/empty
fix(default_content) don't call template() on empty template_name
- Loading branch information
Showing
3 changed files
with
48 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
module Puppet::Parser::Functions | ||
Puppet::Parser::Functions.newfunction(:default_content, | ||
:type => :rvalue, | ||
:doc => <<-'ENDOFDOC' | ||
Takes an optional content and an optional template name and returns the | ||
contents of a file. | ||
Puppet::Parser::Functions.newfunction(:default_content, | ||
:type => :rvalue, | ||
:doc => <<-'ENDOFDOC' | ||
Takes an optional content and an optional template name and returns the | ||
contents of a file. | ||
Examples: | ||
Examples: | ||
$config_file_content = default_content($config_file_string, $config_file_template) | ||
file { '/tmp/x': | ||
ensure => 'file', | ||
content => $config_file_content, | ||
} | ||
ENDOFDOC | ||
) do |args| | ||
content = args[0] | ||
template_name = args[1] | ||
$config_file_content = default_content($file_content, $template_location) | ||
file { '/tmp/x': | ||
ensure => 'file', | ||
content => $config_file_content, | ||
} | ||
ENDOFDOC | ||
) do |args| | ||
content = args[0] | ||
template_name = args[1] | ||
|
||
# Load template function from puppet | ||
Puppet::Parser::Functions.function('template') | ||
# Load template function from puppet | ||
Puppet::Parser::Functions.function('template') | ||
|
||
return content if content != '' | ||
return function_template([template_name]) if template_name | ||
emptyish = ->(x) { return (x.nil? || x.empty? || x == :undef) } | ||
|
||
return nil | ||
end | ||
return content unless emptyish[content] | ||
return function_template([template_name]) unless emptyish[template_name] | ||
|
||
return :undef | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
require 'spec_helper' | ||
|
||
describe 'default_content' do | ||
describe 'signature validation' do | ||
it 'should exist' do | ||
is_expected.not_to be_nil | ||
end | ||
end | ||
|
||
context 'should return the correct string for' do | ||
it 'a string' do | ||
is_expected.to run.with_params('a string', :undef).and_return 'a string' | ||
end | ||
it 'an empty string and a template' do | ||
tw = 'a template string' | ||
Puppet::Parser::TemplateWrapper.stubs(:new).returns(tw) | ||
tw.stubs(:file=).with('/tmp/foo.erb') | ||
tw.stubs(:result).returns('a template string') | ||
is_expected.to run.with_params(:undef, '/tmp/foo.erb').and_return 'a template string' | ||
end | ||
it 'an empty string and an empty template' do | ||
is_expected.to run.with_params(:undef, :undef).and_return :undef | ||
end | ||
end | ||
end |