diff options
author | Nigel Kersten <nigelk@google.com> | 2009-07-23 08:34:47 -0700 |
---|---|---|
committer | Paul Nasrat <pnasrat@googlemail.com> | 2009-08-07 11:08:42 +0100 |
commit | be9e484c0daaf4befb0dfbcf85bda08ce6c1effd (patch) | |
tree | 08ab3dd6012df3d198364e66480d9b829a7fcb6d | |
parent | f3ad66f69979cd107025b6edd07bbe6c958d447b (diff) | |
download | facter-be9e484c0daaf4befb0dfbcf85bda08ce6c1effd.tar.gz facter-be9e484c0daaf4befb0dfbcf85bda08ce6c1effd.tar.xz facter-be9e484c0daaf4befb0dfbcf85bda08ce6c1effd.zip |
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
-rw-r--r-- | lib/facter/util/macosx.rb | 10 | ||||
-rwxr-xr-x | spec/unit/util/macosx.rb | 34 |
2 files changed, 41 insertions, 3 deletions
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 |