diff options
author | danielsdeleo <dan@chef.io> | 2015-09-24 15:04:38 -0700 |
---|---|---|
committer | danielsdeleo <dan@chef.io> | 2015-09-24 16:24:14 -0700 |
commit | a37c95afa90666574e6335f8212e0f8fcd4b6f4c (patch) | |
tree | 792ca26e436923a12490708ba6fb52729a3a1c4e /chef-config/spec | |
parent | 37df1cf0bcc8405ba9d01245dd8cf6ebcceb426b (diff) | |
download | chef-a37c95afa90666574e6335f8212e0f8fcd4b6f4c.tar.gz |
Derive locations from expanded path to config filelocal-mode-cache-relative-path
This resolves an issue where running `chef-client -c client.rb -z` will
attempt to create the local mode cache at the filesystem root with an
error like:
```
ERROR: Permission denied @ dir_s_mkdir - /local-mode-cache
```
Diffstat (limited to 'chef-config/spec')
-rw-r--r-- | chef-config/spec/unit/config_spec.rb | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/chef-config/spec/unit/config_spec.rb b/chef-config/spec/unit/config_spec.rb index 395fa2618e..bc35fbee69 100644 --- a/chef-config/spec/unit/config_spec.rb +++ b/chef-config/spec/unit/config_spec.rb @@ -301,14 +301,36 @@ RSpec.describe ChefConfig::Config do describe "setting the config dir" do + context "when the config file is given with a relative path" do + + before do + ChefConfig::Config.config_file = "client.rb" + end + + it "expands the path when determining config_dir" do + # config_dir goes through PathHelper.canonical_path, which + # downcases on windows because the FS is case insensitive, so we + # have to downcase expected and actual to make the tests work. + expect(ChefConfig::Config.config_dir.downcase).to eq(to_platform(Dir.pwd).downcase) + end + + it "does not set derived paths at FS root" do + ChefConfig::Config.local_mode = true + expect(ChefConfig::Config.cache_path.downcase).to eq(to_platform(File.join(Dir.pwd, 'local-mode-cache')).downcase) + end + + end + context "when the config file is /etc/chef/client.rb" do before do - ChefConfig::Config.config_file = to_platform("/etc/chef/client.rb") + config_location = to_platform("/etc/chef/client.rb").downcase + allow(File).to receive(:absolute_path).with(config_location).and_return(config_location) + ChefConfig::Config.config_file = config_location end it "config_dir is /etc/chef" do - expect(ChefConfig::Config.config_dir).to eq(to_platform("/etc/chef")) + expect(ChefConfig::Config.config_dir).to eq(to_platform("/etc/chef").downcase) end context "and chef is running in local mode" do @@ -317,7 +339,7 @@ RSpec.describe ChefConfig::Config do end it "config_dir is /etc/chef" do - expect(ChefConfig::Config.config_dir).to eq(to_platform("/etc/chef")) + expect(ChefConfig::Config.config_dir).to eq(to_platform("/etc/chef").downcase) end end |