diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2017-02-06 18:36:16 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2017-02-07 11:27:09 -0800 |
commit | ac7cda9de8a41754226894336794b7972d33a1b8 (patch) | |
tree | 7a3e4da5307209eac6ec6c253a178d4a58b203fb /lib/chef/mixin/which.rb | |
parent | b7af0810fc7c8437585887dd3abf1b62dc773818 (diff) | |
download | chef-ac7cda9de8a41754226894336794b7972d33a1b8.tar.gz |
add unit tests for `which` behavior
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/mixin/which.rb')
-rw-r--r-- | lib/chef/mixin/which.rb | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/chef/mixin/which.rb b/lib/chef/mixin/which.rb index a81aacd89b..faa46b9594 100644 --- a/lib/chef/mixin/which.rb +++ b/lib/chef/mixin/which.rb @@ -25,8 +25,8 @@ class Chef def where(*cmds, extra_path: nil, &block) # NOTE: unnecessarily duplicates function of path_sanity extra_path ||= [ "/bin", "/usr/bin", "/sbin", "/usr/sbin" ] + paths = env_path.split(File::PATH_SEPARATOR) + extra_path cmds.map do |cmd| - paths = ENV["PATH"].split(File::PATH_SEPARATOR) + extra_path paths.map do |path| filename = Chef.path_to(File.join(path, cmd)) filename if valid_executable?(filename, &block) @@ -36,6 +36,11 @@ class Chef private + # for test stubbing + def env_path + ENV["PATH"] + end + def valid_executable?(filename, &block) return false unless File.executable?(filename) && !File.directory?(filename) block ? yield(filename) : true |