[Pkg-puppet-devel] [SCM] Packaging of Facter for debian branch, upstream, updated. 3a39dd8353b6308cf49522990104cc63e55d7cda

Paul Nasrat pnasrat at googlemail.com
Fri Jan 29 17:22:37 UTC 2010


The following commit has been merged in the upstream branch:
commit be9e484c0daaf4befb0dfbcf85bda08ce6c1effd
Author: Nigel Kersten <nigelk at google.com>
Date:   Thu Jul 23 08:34:47 2009 -0700

    Update OS X minor version fact to cope with '10.x' values and provide test coverage
    switch %x{} call to Facter::Util::Resolution.exec for better testing

diff --git a/lib/facter/util/macosx.rb b/lib/facter/util/macosx.rb
index f5f83f3..6754f18 100644
--- a/lib/facter/util/macosx.rb
+++ b/lib/facter/util/macosx.rb
@@ -56,12 +56,16 @@ module Facter::Util::Macosx
     def self.sw_vers
         ver = Hash.new
         [ "productName", "productVersion", "buildVersion" ].each do |option|
-            ver["macosx_#{option}"] = %x{sw_vers -#{option}}.strip
+            ver["macosx_#{option}"] = Facter::Util::Resolution.exec("/usr/bin/sw_vers -#{option}").strip
         end
         productversion = ver["macosx_productVersion"]
         if not productversion.nil?
-            ver["macosx_productversion_major"] = productversion.scan(/(\d+\.\d+)/)[0][0]
-            ver["macosx_productversion_minor"] = productversion.scan(/(\d+)\.(\d+)\.(\d+)/)[0].last
+            versions = productversion.scan(/(\d+)\.(\d+)\.*(\d*)/)[0]
+            ver["macosx_productversion_major"] = "#{versions[0]}.#{versions[1]}"
+            if versions[2].empty?  # 10.x should be treated as 10.x.0
+                versions[2] = "0"
+            end
+            ver["macosx_productversion_minor"] = versions[2]
         end
         ver
     end
diff --git a/spec/unit/util/macosx.rb b/spec/unit/util/macosx.rb
index a543013..283fe75 100755
--- a/spec/unit/util/macosx.rb
+++ b/spec/unit/util/macosx.rb
@@ -44,4 +44,38 @@ describe Facter::Util::Macosx do
         Facter::Util::Macosx.expects(:profiler_data).with("SPSoftwareDataType").returns "eh"
         Facter::Util::Macosx.os_overview.should == "eh"
     end
+    
+    describe "when working out software version" do
+        
+        before do
+            Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productName").returns "Mac OS X"
+            Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -buildVersion").returns "9J62"
+        end
+        
+        it "should have called sw_vers three times when determining software version" do
+            Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productVersion").returns "10.5.7"
+            Facter::Util::Macosx.sw_vers
+        end
+    
+        it "should return a hash with the correct keys when determining software version" do
+            Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productVersion").returns "10.5.7"
+            Facter::Util::Macosx.sw_vers.keys.sort.should == ["macosx_productName",
+                                                              "macosx_buildVersion",
+                                                              "macosx_productversion_minor",
+                                                              "macosx_productversion_major",
+                                                              "macosx_productVersion"].sort
+        end
+    
+        it "should split a product version of 'x.y.z' into separate hash entries correctly" do
+            Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productVersion").returns "1.2.3"
+            sw_vers = Facter::Util::Macosx.sw_vers
+            sw_vers["macosx_productversion_major"].should == "1.2"
+            sw_vers["macosx_productversion_minor"].should == "3"
+        end
+    
+        it "should treat a product version of 'x.y' as 'x.y.0" do
+            Facter::Util::Resolution.expects(:exec).with("/usr/bin/sw_vers -productVersion").returns "2.3"
+            Facter::Util::Macosx.sw_vers["macosx_productversion_minor"].should == "0"
+        end
+    end
 end

-- 
Packaging of Facter for debian



More information about the Pkg-puppet-devel mailing list