summaryrefslogtreecommitdiff
path: root/chef-config/spec
diff options
context:
space:
mode:
authorJohn Kerry <john@kerryhouse.net>2016-11-09 04:25:11 -0500
committerThom May <thom@may.lt>2016-11-09 09:25:11 +0000
commit94ebcc4b16d8ce554db8cb18a37dfce3436d12b0 (patch)
treee3407e66ef9ea62e4066b99a2f81e24dc58dd19f /chef-config/spec
parent975d1e68ddf8fd4103e79aa0b8d08aef9560deee (diff)
downloadchef-94ebcc4b16d8ce554db8cb18a37dfce3436d12b0.tar.gz
Windows: search for config on same drive as executable location (#5478)
* changing the default drive for the config file to be the drive that the executable is launched from. This should allow for an easier launch of chef from a d: drive installation Signed-off-by: John Kerry <john@kerryhouse.net> * adding a check and a fallback to systemdrive for the base path when __FILE__ path doesn't have a drive (appears with linux hosts running windows targeted unit tests) Signed-off-by: John Kerry <john@kerryhouse.net> * fixing rubocop errors Signed-off-by: John Kerry <john@kerryhouse.net> * adding a __FILE__ path override for cache_path tests Signed-off-by: John Kerry <john@kerryhouse.net>
Diffstat (limited to 'chef-config/spec')
-rw-r--r--chef-config/spec/unit/config_spec.rb46
1 files changed, 38 insertions, 8 deletions
diff --git a/chef-config/spec/unit/config_spec.rb b/chef-config/spec/unit/config_spec.rb
index 806ab7d4fa..f5e9a914c9 100644
--- a/chef-config/spec/unit/config_spec.rb
+++ b/chef-config/spec/unit/config_spec.rb
@@ -203,16 +203,41 @@ RSpec.describe ChefConfig::Config do
before :each do
allow(ChefConfig).to receive(:windows?).and_return(is_windows)
end
-
+ describe "class method: windows_installation_drive" do
+ before do
+ allow(File).to receive(:expand_path).and_return("D:/Path/To/Executable")
+ end
+ if is_windows
+ it "should return D: on a windows system" do
+ expect(ChefConfig::Config.windows_installation_drive).to eq("D:")
+ end
+ else
+ it "should return nil on a non-windows system" do
+ expect(ChefConfig::Config.windows_installation_drive).to eq(nil)
+ end
+ end
+ end
describe "class method: platform_specific_path" do
+ before do
+ allow(ChefConfig::Config).to receive(:env).and_return({ "SYSTEMDRIVE" => "C:" })
+ end
if is_windows
- it "should return a windows path on windows systems" do
- path = "/etc/chef/cookbooks"
- allow(ChefConfig::Config).to receive(:env).and_return({ "SYSTEMDRIVE" => "C:" })
- # match on a regex that looks for the base path with an optional
- # system drive at the beginning (c:)
- # system drive is not hardcoded b/c it can change and b/c it is not present on linux systems
- expect(ChefConfig::Config.platform_specific_path(path)).to eq("C:\\chef\\cookbooks")
+ path = "/etc/chef/cookbooks"
+ context "a windows system with chef installed on C: drive" do
+ before do
+ allow(ChefConfig::Config).to receive(:windows_installation_drive).and_return("C:")
+ end
+ it "should return a windows path rooted in C:" do
+ expect(ChefConfig::Config.platform_specific_path(path)).to eq("C:\\chef\\cookbooks")
+ end
+ end
+ context "a windows system with chef installed on D: drive" do
+ before do
+ allow(ChefConfig::Config).to receive(:windows_installation_drive).and_return("D:")
+ end
+ it "should return a windows path rooted in D:" do
+ expect(ChefConfig::Config.platform_specific_path(path)).to eq("D:\\chef\\cookbooks")
+ end
end
else
it "should return given path on non-windows systems" do
@@ -345,6 +370,11 @@ RSpec.describe ChefConfig::Config do
end
describe "ChefConfig::Config[:cache_path]" do
+ before do
+ if is_windows
+ allow(File).to receive(:expand_path).and_return("#{ChefConfig::Config.env["SYSTEMDRIVE"]}/Path/To/Executable")
+ end
+ end
context "when /var/chef exists and is accessible" do
it "defaults to /var/chef" do
allow(ChefConfig::Config).to receive(:path_accessible?).with(to_platform("/var/chef")).and_return(true)