From f80bd5e41623f2bdb8c5495caa12274c36e1cad3 Mon Sep 17 00:00:00 2001 From: luke Date: Thu, 1 Feb 2007 19:24:58 +0000 Subject: Fixing exec so it actually works when path is specified as an array git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2155 980ebf18-57e1-0310-9a29-db15c13687c0 --- lib/puppet/type/exec.rb | 2 +- test/test | 3 +++ test/types/exec.rb | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb index 04ba9fa6c..01870770c 100755 --- a/lib/puppet/type/exec.rb +++ b/lib/puppet/type/exec.rb @@ -179,7 +179,7 @@ module Puppet # Support both arrays and colon-separated fields. def value=(*values) - @value = values.collect { |val| + @value = values.flatten.collect { |val| val.split(":") }.flatten end diff --git a/test/test b/test/test index 586f4957a..5939b862a 100755 --- a/test/test +++ b/test/test @@ -10,6 +10,7 @@ require 'getoptlong' include Find result = GetoptLong.new( + [ "--build", "-b", GetoptLong::NO_ARGUMENT ], [ "--debug", "-d", GetoptLong::NO_ARGUMENT ], [ "--verbose", "-v", GetoptLong::NO_ARGUMENT ], [ "--help", "-h", GetoptLong::NO_ARGUMENT ] @@ -21,6 +22,8 @@ $options = {} result.each { |opt,arg| case opt + when "--build" + $options[:build] = true when "--verbose" $options[:verbose] = true when "--debug" diff --git a/test/types/exec.rb b/test/types/exec.rb index 918fa62be..7718825ee 100755 --- a/test/types/exec.rb +++ b/test/types/exec.rb @@ -641,6 +641,27 @@ and stuff" ) end end + + # make sure paths work both as arrays and strings + def test_paths_as_arrays + path = %w{/usr/bin /usr/sbin /sbin} + exec = nil + assert_nothing_raised("Could not use an array for the path") do + exec = Puppet::Type.type(:exec).create(:command => "echo yay", + :path => path) + end + assert_equal(path, exec[:path], "array-based path did not match") + assert_nothing_raised("Could not use a string for the path") do + exec = Puppet::Type.type(:exec).create(:command => "echo yay", + :path => path.join(":")) + end + assert_equal(path, exec[:path], "string-based path did not match") + assert_nothing_raised("Could not use a colon-separated strings in an array for the path") do + exec = Puppet::Type.type(:exec).create(:command => "echo yay", + :path => ["/usr/bin", "/usr/sbin:/sbin"]) + end + assert_equal(path, exec[:path], "colon-separated array path did not match") + end end # $Id$ -- cgit