[Pkg-puppet-devel] [facter] 158/180: (#190) Don't set external facts when ENV['HOME'] is nil

Stig Sandbeck Mathisen ssm at debian.org
Mon Jun 30 15:06:43 UTC 2014


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository facter.

commit 5cc6ff04071da082a83445869951ede7a70f0f9f
Author: Cassiano Leal <cassiano.leal at gamesys.co.uk>
Date:   Thu Jun 12 15:29:27 2014 +0100

    (#190) Don't set external facts when ENV['HOME'] is nil
---
 lib/facter/util/config.rb     |  4 +++-
 spec/unit/util/config_spec.rb | 14 +++++++++++---
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/lib/facter/util/config.rb b/lib/facter/util/config.rb
index 1d244a8..1a6eff9 100644
--- a/lib/facter/util/config.rb
+++ b/lib/facter/util/config.rb
@@ -45,8 +45,10 @@ module Facter::Util::Config
       else
         @external_facts_dirs = [File.join(windows_dir, 'PuppetLabs', 'facter', 'facts.d')]
       end
+    elsif ENV['HOME']
+      @external_facts_dirs = [File.expand_path(File.join(ENV['HOME'], ".facter", "facts.d"))]
     else
-      @external_facts_dirs = [File.expand_path(File.join("#{ENV['HOME']}", ".facter", "facts.d"))]
+      @external_facts_dirs = []
     end
   end
 
diff --git a/spec/unit/util/config_spec.rb b/spec/unit/util/config_spec.rb
index 7da1f3f..529f001 100644
--- a/spec/unit/util/config_spec.rb
+++ b/spec/unit/util/config_spec.rb
@@ -5,9 +5,17 @@ require 'spec_helper'
 describe Facter::Util::Config do
   include PuppetlabsSpec::Files
 
-  it "should not crash when there's no $HOME set on the environment" do
-    ENV['HOME'] = nil
-    lambda { Facter::Util::Config.setup_default_ext_facts_dirs }.should_not raise_exception
+  describe "ENV['HOME'] is unset" do
+    around do |example|
+      Facter::Core::Execution.with_env('HOME' => nil) do
+        example.run
+      end
+    end
+
+    it "should not set @external_facts_dirs" do
+      Facter::Util::Config.setup_default_ext_facts_dirs
+      Facter::Util::Config.external_facts_dirs.should be_empty
+    end
   end
 
   describe "is_windows? function" do

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-puppet/facter.git



More information about the Pkg-puppet-devel mailing list