Please review pull request #478: (#12490) fixing windows spec tests opened by (cprice-puppet)

Description:

This should fix the failures in exec_spec.rb and util_spec.rb. Has
been tested on Win2k3.

  • Opened: Thu Feb 09 17:46:15 UTC 2012
  • Based on: puppetlabs:master (76d05c25a71ec9cde27ba83884cdb7cebcb26320)
  • Requested merge: cprice-puppet:bug/master/12490-execution_spec-sets-ENV (c8042755e159aef4459c01686e22103786747ee1)

Diff follows:

diff --git a/lib/puppet/util/execution.rb b/lib/puppet/util/execution.rb
index 2833ece..3bdc814 100644
--- a/lib/puppet/util/execution.rb
+++ b/lib/puppet/util/execution.rb
@@ -1,4 +1,5 @@
 module Puppet
+  require 'rbconfig'
 
   # A command failed to execute.
   require 'puppet/error'
@@ -123,7 +124,12 @@ def self.execute(command, arguments = {})
     output
   end
 
-
+  # get the path to the ruby executable (available via Config object, even if it's not in the PATH... so this
+  # is slightly safer than just using Puppet::Util.which)
+  def self.ruby_path()
+    File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'] + Config::CONFIG['EXEEXT']).
+        sub(/.*\s.*/m, '"\&"')
+  end
 
   # Because some modules provide their own version of this method.
   class << self
diff --git a/spec/unit/type/exec_spec.rb b/spec/unit/type/exec_spec.rb
index 1effbb4..0fb412b 100755
--- a/spec/unit/type/exec_spec.rb
+++ b/spec/unit/type/exec_spec.rb
@@ -379,15 +379,13 @@ def test(command, valid)
       end
 
       it "should fail if timeout is exceeded" do
-        Puppet::Util.stubs(:execute).with do |cmd,args|
-          sleep 1
-          true
-        end
-        FileTest.stubs(:file?).returns(false)
-        FileTest.stubs(:file?).with(File.expand_path('/bin/sleep')).returns(true)
-        FileTest.stubs(:executable?).returns(false)
-        FileTest.stubs(:executable?).with(File.expand_path('/bin/sleep')).returns(true)
-        sleep_exec = Puppet::Type.type(:exec).new(:name => 'sleep 1', :path => [File.expand_path('/bin')], :timeout => '0.2')
+        ruby_path = Puppet::Util::Execution.ruby_path()
+
+        ## Leaving this commented version in here because it fails on windows, due to what appears to be
+        ##  an assumption about hash iteration order in lib/puppet/type.rb#hash2resource, where
+        ##  resource[]= will overwrite the namevar with ":name" if the iteration is in the wrong order
+        #sleep_exec = Puppet::Type.type(:exec).new(:name => 'exec_spec sleep command', :command => "#{ruby_path} -e 'sleep 0.02'", :timeout => '0.01')
+        sleep_exec = Puppet::Type.type(:exec).new(:name => "#{ruby_path} -e 'sleep 0.02'", :timeout => '0.01')
 
         lambda { sleep_exec.refresh }.should raise_error Puppet::Error, "Command exceeded timeout"
       end
diff --git a/spec/unit/util_spec.rb b/spec/unit/util_spec.rb
index 3561f01..0d1a2d0 100755
--- a/spec/unit/util_spec.rb
+++ b/spec/unit/util_spec.rb
@@ -217,9 +217,11 @@
     end
 
     it "should warn if the user's HOME is not set but their PATH contains a ~" do
-      Puppet::Util.withenv({:HOME => nil, :PATH => "~/bin:/usr/bin:/bin"}) do
+      env_path = %w[~/bin /usr/bin /bin].join(File::PATH_SEPARATOR)
+
+      Puppet::Util.withenv({:HOME => nil, :PATH => env_path}) do
         Puppet::Util::Warnings.expects(:warnonce).once
-        Puppet::Util.which('foo').should_not be_nil
+        Puppet::Util.which('foo')
       end
     end
 

    

--
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.

Reply via email to