+1 On Jul 23, 2009, at 10:48 AM, Nigel Kersten wrote:
> > > Signed-off-by: Nigel Kersten <[email protected]> > --- > lib/facter/util/macosx.rb | 10 +++++++--- > 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 > -- > 1.6.3.3 > > > > -- To have a right to do a thing is not at all the same as to be right in doing it. -- G. K. Chesterton --------------------------------------------------------------------- Luke Kanies | http://reductivelabs.com | http://madstop.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en -~----------~----~----~----~------~----~------~--~---
