diff options
author | Tim Smith <tsmith@chef.io> | 2020-07-23 17:08:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-23 17:08:08 -0700 |
commit | 05ad687b5082389bdb9b1a17e843d56e86c2f1a8 (patch) | |
tree | 9da3b76c5be2b33d88924d1b9c0b6610201afce5 /spec | |
parent | e48341724607e2fdfecfe74f2a7b80ea1ff6185a (diff) | |
parent | df3f9fa4f950827b028efb58b1403f8e4c6f3d08 (diff) | |
download | chef-05ad687b5082389bdb9b1a17e843d56e86c2f1a8.tar.gz |
Merge pull request #10193 from chef/lcg/default-paths
Implement default_paths API
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/mixin/default_paths_spec.rb (renamed from spec/unit/mixin/path_sanity_spec.rb) | 28 | ||||
-rw-r--r-- | spec/unit/mixin/shell_out_spec.rb | 14 |
2 files changed, 21 insertions, 21 deletions
diff --git a/spec/unit/mixin/path_sanity_spec.rb b/spec/unit/mixin/default_paths_spec.rb index 013225f853..0224b8f4ce 100644 --- a/spec/unit/mixin/path_sanity_spec.rb +++ b/spec/unit/mixin/default_paths_spec.rb @@ -18,19 +18,19 @@ require "spec_helper" -class PathSanityTestHarness - include Chef::Mixin::PathSanity +class DefaultPathsTestHarness + include Chef::Mixin::DefaultPaths end -describe Chef::Mixin::PathSanity do +describe Chef::Mixin::DefaultPaths do before do - @sanity = PathSanityTestHarness.new + @default_paths = DefaultPathsTestHarness.new end - describe "when enforcing path sanity" do + describe "when enforcing default paths" do before do - Chef::Config[:enforce_path_sanity] = true + Chef::Config[:enforce_default_paths] = true @ruby_bindir = "/some/ruby/bin" @gem_bindir = "/some/gem/bin" allow(Gem).to receive(:bindir).and_return(@gem_bindir) @@ -40,41 +40,41 @@ describe Chef::Mixin::PathSanity do it "adds all useful PATHs even if environment is an empty hash" do env = {} - @sanity.enforce_path_sanity(env) + @default_paths.enforce_default_paths(env) expect(env["PATH"]).to eq("#{@gem_bindir}:#{@ruby_bindir}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin") end it "adds all useful PATHs that are not yet in PATH to PATH" do env = { "PATH" => "" } - @sanity.enforce_path_sanity(env) + @default_paths.enforce_default_paths(env) expect(env["PATH"]).to eq("#{@gem_bindir}:#{@ruby_bindir}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin") end it "does not re-add paths that already exist in PATH" do env = { "PATH" => "/usr/bin:/sbin:/bin" } - @sanity.enforce_path_sanity(env) + @default_paths.enforce_default_paths(env) expect(env["PATH"]).to eq("#{@gem_bindir}:#{@ruby_bindir}:/usr/bin:/sbin:/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin") end it "creates path with utf-8 encoding" do env = { "PATH" => "/usr/bin:/sbin:/bin:/b#{0x81.chr}t".force_encoding("ISO-8859-1") } - @sanity.enforce_path_sanity(env) + @default_paths.enforce_default_paths(env) expect(env["PATH"].encoding.to_s).to eq("UTF-8") end it "adds the current executing Ruby's bindir and Gem bindir to the PATH" do env = { "PATH" => "" } - @sanity.enforce_path_sanity(env) + @default_paths.enforce_default_paths(env) expect(env["PATH"]).to eq("#{@gem_bindir}:#{@ruby_bindir}:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin") end - it "does not create entries for Ruby/Gem bindirs if they exist in SANE_PATH or PATH" do + it "does not create entries for Ruby/Gem bindirs if they exist in PATH" do ruby_bindir = "/usr/bin" gem_bindir = "/yo/gabba/gabba" allow(Gem).to receive(:bindir).and_return(gem_bindir) allow(RbConfig::CONFIG).to receive(:[]).with("bindir").and_return(ruby_bindir) env = { "PATH" => gem_bindir } - @sanity.enforce_path_sanity(env) + @default_paths.enforce_default_paths(env) expect(env["PATH"]).to eq("/usr/bin:/yo/gabba/gabba:/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin:/bin") end @@ -85,7 +85,7 @@ describe Chef::Mixin::PathSanity do allow(RbConfig::CONFIG).to receive(:[]).with("bindir").and_return(ruby_bindir) allow(ChefUtils).to receive(:windows?).and_return(true) env = { "PATH" => 'C:\Windows\system32;C:\mr\softie' } - @sanity.enforce_path_sanity(env) + @default_paths.enforce_default_paths(env) expect(env["PATH"]).to eq("#{gem_bindir};#{ruby_bindir};C:\\Windows\\system32;C:\\mr\\softie") end end diff --git a/spec/unit/mixin/shell_out_spec.rb b/spec/unit/mixin/shell_out_spec.rb index 5880aa2b6a..2b76a10e6c 100644 --- a/spec/unit/mixin/shell_out_spec.rb +++ b/spec/unit/mixin/shell_out_spec.rb @@ -21,7 +21,7 @@ # require "spec_helper" -require "chef/mixin/path_sanity" +require "chef/mixin/default_paths" describe Chef::Mixin::ShellOut do let(:shell_out_class) { Class.new { include Chef::Mixin::ShellOut } } @@ -74,7 +74,7 @@ describe Chef::Mixin::ShellOut do "LC_ALL" => Chef::Config[:internal_locale], "LANG" => Chef::Config[:internal_locale], "LANGUAGE" => Chef::Config[:internal_locale], - env_path => shell_out_obj.sanitized_path, + env_path => shell_out_obj.default_paths, }).and_return(retobj) shell_out_obj.send(method, cmd, **options) end @@ -87,7 +87,7 @@ describe Chef::Mixin::ShellOut do "LC_ALL" => Chef::Config[:internal_locale], "LANG" => Chef::Config[:internal_locale], "LANGUAGE" => Chef::Config[:internal_locale], - env_path => shell_out_obj.sanitized_path, + env_path => shell_out_obj.default_paths, }).and_return(retobj) shell_out_obj.send(method, cmd, **options) expect(options[:environment].key?("LC_ALL")).to be false @@ -115,7 +115,7 @@ describe Chef::Mixin::ShellOut do "LC_ALL" => Chef::Config[:internal_locale], "LANG" => Chef::Config[:internal_locale], "LANGUAGE" => Chef::Config[:internal_locale], - env_path => shell_out_obj.sanitized_path, + env_path => shell_out_obj.default_paths, }).and_return(retobj) shell_out_obj.send(method, cmd, **options) end @@ -128,7 +128,7 @@ describe Chef::Mixin::ShellOut do "LC_ALL" => Chef::Config[:internal_locale], "LANG" => Chef::Config[:internal_locale], "LANGUAGE" => Chef::Config[:internal_locale], - env_path => shell_out_obj.sanitized_path, + env_path => shell_out_obj.default_paths, }).and_return(retobj) shell_out_obj.send(method, cmd, **options) expect(options[:env].key?("LC_ALL")).to be false @@ -144,7 +144,7 @@ describe Chef::Mixin::ShellOut do "LC_ALL" => Chef::Config[:internal_locale], "LANG" => Chef::Config[:internal_locale], "LANGUAGE" => Chef::Config[:internal_locale], - env_path => shell_out_obj.sanitized_path, + env_path => shell_out_obj.default_paths, }).and_return(retobj) shell_out_obj.send(method, cmd, **options) end @@ -158,7 +158,7 @@ describe Chef::Mixin::ShellOut do "LC_ALL" => Chef::Config[:internal_locale], "LANG" => Chef::Config[:internal_locale], "LANGUAGE" => Chef::Config[:internal_locale], - env_path => shell_out_obj.sanitized_path, + env_path => shell_out_obj.default_paths, }).and_return(retobj) shell_out_obj.send(method, cmd) end |