From c3ee6dfcd867064ccbf07f564b613b128859eba5 Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Wed, 6 Feb 2019 18:26:45 +0530 Subject: Uniform config dir path separator - Return canonical path for user_home dir for the config_dir. Signed-off-by: Vivek Singh --- chef-config/lib/chef-config/config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb index a12a44a075..f6e481b244 100644 --- a/chef-config/lib/chef-config/config.rb +++ b/chef-config/lib/chef-config/config.rb @@ -122,7 +122,7 @@ module ChefConfig if config_file PathHelper.dirname(PathHelper.canonical_path(config_file, false)) else - PathHelper.join(user_home, ".chef", "") + PathHelper.join(PathHelper.canonical_path(user_home, false), ".chef", "") end end -- cgit v1.2.1 From 35be84501c549800ccdbd8570befcbd3099048dd Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Thu, 7 Feb 2019 12:49:49 +0530 Subject: Use cleanpath helper method instead canonical_path -Previously to make user_home uniform canonical_path is used that it implemented in a way to add an absolute path. Signed-off-by: Vivek Singh --- chef-config/lib/chef-config/config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb index f6e481b244..1c921eac72 100644 --- a/chef-config/lib/chef-config/config.rb +++ b/chef-config/lib/chef-config/config.rb @@ -122,7 +122,7 @@ module ChefConfig if config_file PathHelper.dirname(PathHelper.canonical_path(config_file, false)) else - PathHelper.join(PathHelper.canonical_path(user_home, false), ".chef", "") + PathHelper.join(PathHelper.cleanpath(user_home), ".chef", "") end end -- cgit v1.2.1 From 7dc9e6c404e698f87beadf14f73f1dda4c505421 Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Fri, 8 Feb 2019 23:00:23 +0530 Subject: Added specs Signed-off-by: Vivek Singh --- chef-config/spec/unit/config_spec.rb | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/chef-config/spec/unit/config_spec.rb b/chef-config/spec/unit/config_spec.rb index 7e32a1e742..b6e88f0bc8 100644 --- a/chef-config/spec/unit/config_spec.rb +++ b/chef-config/spec/unit/config_spec.rb @@ -644,11 +644,11 @@ RSpec.describe ChefConfig::Config do context "when the user's home dir is /home/charlie/" do before do - ChefConfig::Config.user_home = to_platform("/home/charlie") + ChefConfig::Config.user_home = "/home/charlie/" end it "config_dir is /home/charlie/.chef/" do - expect(ChefConfig::Config.config_dir).to eq(ChefConfig::PathHelper.join(to_platform("/home/charlie/.chef"), "")) + expect(ChefConfig::Config.config_dir).to eq(ChefConfig::PathHelper.join(ChefConfig::PathHelper.cleanpath("/home/charlie/"), ".chef", "")) end context "and chef is running in local mode" do @@ -657,11 +657,34 @@ RSpec.describe ChefConfig::Config do end it "config_dir is /home/charlie/.chef/" do - expect(ChefConfig::Config.config_dir).to eq(ChefConfig::PathHelper.join(to_platform("/home/charlie/.chef"), "")) + expect(ChefConfig::Config.config_dir).to eq(ChefConfig::PathHelper.join(ChefConfig::PathHelper.cleanpath("/home/charlie/"), ".chef", "")) end end end + if is_windows + context "when the user's home dir is windows specific" do + before do + ChefConfig::Config.user_home = to_platform("/home/charlie/") + end + + it "config_dir is with backslashes" do + expect(ChefConfig::Config.config_dir).to eq(ChefConfig::PathHelper.join(ChefConfig::PathHelper.cleanpath("/home/charlie/"), ".chef", "")) + end + + context "and chef is running in local mode" do + before do + ChefConfig::Config.local_mode = true + end + + it "config_dir is with backslashes" do + expect(ChefConfig::Config.config_dir).to eq(ChefConfig::PathHelper.join(ChefConfig::PathHelper.cleanpath("/home/charlie/"), ".chef", "")) + end + end + end + + end + end if is_windows -- cgit v1.2.1