Merge branch 'pull-201'
This closes GH-201.
This commit is contained in:
commit
e49d356fbf
2 changed files with 16 additions and 11 deletions
|
@ -1,7 +1,6 @@
|
|||
#
|
||||
# ensure_packages.rb
|
||||
#
|
||||
require 'puppet/parser/functions'
|
||||
|
||||
module Puppet::Parser::Functions
|
||||
newfunction(:ensure_packages, :type => :statement, :doc => <<-EOS
|
||||
|
@ -9,13 +8,15 @@ Takes a list of packages and only installs them if they don't already exist.
|
|||
EOS
|
||||
) do |arguments|
|
||||
|
||||
raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1)") if arguments.size != 1
|
||||
raise(Puppet::ParseError, "ensure_packages(): Requires array " +
|
||||
"given (#{arguments[0].class})") if !arguments[0].kind_of?(Array)
|
||||
if arguments.size != 1
|
||||
raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments " +
|
||||
"given (#{arguments.size} for 1)")
|
||||
end
|
||||
|
||||
packages = Array(arguments[0])
|
||||
|
||||
Puppet::Parser::Functions.function(:ensure_resource)
|
||||
arguments[0].each { |package_name|
|
||||
packages.each { |package_name|
|
||||
function_ensure_resource(['package', package_name, {'ensure' => 'present' } ])
|
||||
}
|
||||
end
|
||||
|
|
|
@ -8,13 +8,17 @@ describe 'ensure_packages' do
|
|||
|
||||
describe 'argument handling' do
|
||||
it 'fails with no arguments' do
|
||||
should run.with_params().and_raise_error(Puppet::ParseError)
|
||||
expect {
|
||||
scope.function_ensure_packages([])
|
||||
}.to raise_error(Puppet::ParseError, /0 for 1/)
|
||||
end
|
||||
it 'requires an array' do
|
||||
lambda { scope.function_ensure_packages([['foo']]) }.should_not raise_error
|
||||
|
||||
it 'accepts an array of values' do
|
||||
scope.function_ensure_packages([['foo']])
|
||||
end
|
||||
it 'fails when given a string' do
|
||||
should run.with_params('foo').and_raise_error(Puppet::ParseError)
|
||||
|
||||
it 'accepts a single package name as a string' do
|
||||
scope.function_ensure_packages(['foo'])
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue