From 56a83067f8592b63960fa95af0f49b80cd4c5c9a Mon Sep 17 00:00:00 2001 From: John Keiser Date: Thu, 5 Jun 2014 14:19:12 -0700 Subject: Use path_join to create local-mode-cache Always give config_dir a value --- lib/chef/config.rb | 10 +++--- spec/unit/config_spec.rb | 79 ++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 68 insertions(+), 21 deletions(-) diff --git a/lib/chef/config.rb b/lib/chef/config.rb index dd1b44661b..c87cfcaaa7 100644 --- a/lib/chef/config.rb +++ b/lib/chef/config.rb @@ -101,10 +101,10 @@ class Chef configurable(:config_file) default(:config_dir) do - if local_mode - path_join(user_home, ".chef#{platform_path_separator}") + if config_file + ::File.dirname(config_file) else - config_file && ::File.dirname(config_file) + path_join(user_home, ".chef#{platform_path_separator}") end end @@ -238,7 +238,7 @@ class Chef # this is under the user's home directory. default(:cache_path) do if local_mode - "#{config_dir}local-mode-cache" + path_join(config_dir, 'local-mode-cache') else primary_cache_root = platform_specific_path("/var") primary_cache_path = platform_specific_path("/var/chef") @@ -384,7 +384,7 @@ class Chef # certificates in this directory will be added to whatever CA bundle ruby # is using. Use this to add self-signed certs for your Chef Server or local # HTTP file servers. - default(:trusted_certs_dir) { config_dir && path_join(config_dir, "trusted_certs") } + default(:trusted_certs_dir) { path_join(config_dir, "trusted_certs") } # Where should chef-solo download recipes from? default :recipe_url, nil diff --git a/spec/unit/config_spec.rb b/spec/unit/config_spec.rb index c467d7d553..6b49fa8d6a 100644 --- a/spec/unit/config_spec.rb +++ b/spec/unit/config_spec.rb @@ -198,6 +198,32 @@ describe Chef::Config do Chef::Config[:cache_path].should == secondary_cache_path end end + + context "when chef is running in local mode" do + before do + Chef::Config.local_mode = true + end + + context "and config_dir is /a/b/c" do + before do + Chef::Config.config_dir '/a/b/c' + end + + it "cache_path is /a/b/c/local-mode-cache" do + Chef::Config.cache_path.should == '/a/b/c/local-mode-cache' + end + end + + context "and config_dir is /a/b/c/" do + before do + Chef::Config.config_dir '/a/b/c/' + end + + it "cache_path is /a/b/c/local-mode-cache" do + Chef::Config.cache_path.should == '/a/b/c/local-mode-cache' + end + end + end end it "Chef::Config[:file_backup_path] defaults to /var/chef/backup" do @@ -266,35 +292,56 @@ describe Chef::Config do describe "setting the config dir" do - before do - Chef::Config.stub(:on_windows?).and_return(false) - Chef::Config.config_file = "/etc/chef/client.rb" - end + context "when the config file is /etc/chef/client.rb" do - context "by default" do - it "is the parent dir of the config file" do + before do + Chef::Config.stub(:on_windows?).and_return(false) + Chef::Config.config_file = "/etc/chef/client.rb" + end + + it "config_dir is /etc/chef" do Chef::Config.config_dir.should == "/etc/chef" end + + context "and chef is running in local mode" do + before do + Chef::Config.local_mode = true + end + + it "config_dir is /etc/chef" do + Chef::Config.config_dir.should == "/etc/chef" + end + end + + context "when config_dir is set to /other/config/dir/" do + before do + Chef::Config.config_dir = "/other/config/dir/" + end + + it "yields the explicit value" do + Chef::Config.config_dir.should == "/other/config/dir/" + end + end + end - context "when chef is running in local mode" do + context "when the user's home dir is /home/charlie" do before do - Chef::Config.local_mode = true Chef::Config.user_home = "/home/charlie" end - it "is in the user's home dir" do + it "config_dir is /home/charlie/.chef" do Chef::Config.config_dir.should == "/home/charlie/.chef/" end - end - context "when explicitly set" do - before do - Chef::Config.config_dir = "/other/config/dir/" - end + context "and chef is running in local mode" do + before do + Chef::Config.local_mode = true + end - it "uses the explicit value" do - Chef::Config.config_dir.should == "/other/config/dir/" + it "config_dir is /home/charlie/.chef" do + Chef::Config.config_dir.should == "/home/charlie/.chef/" + end end end -- cgit v1.2.1