Revised a few of the new tests for the exec type and provider to
ensure that they were testing what they meant to, and added in a
couple of new tests.

Reviewed-by:Daniel Pittman

Signed-off-by: Max Martin <[email protected]>
---
 lib/puppet/type/exec.rb               |    2 +-
 spec/unit/provider/exec/posix_spec.rb |   13 +++++++++----
 spec/unit/provider/exec/shell_spec.rb |   18 ++++++++++++------
 3 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb
index 67d40a7..4458bf0 100755
--- a/lib/puppet/type/exec.rb
+++ b/lib/puppet/type/exec.rb
@@ -139,7 +139,7 @@ module Puppet
     newparam(:path) do
       desc "The search path used for command execution.
         Commands must be fully qualified if no path is specified.  Paths
-        can be specified as an array or as a colon or semi-colon separated 
list."
+        can be specified as an array or as a colon separated list."
 
       # Support both arrays and colon-separated fields.
       def value=(*values)
diff --git a/spec/unit/provider/exec/posix_spec.rb 
b/spec/unit/provider/exec/posix_spec.rb
index a9b2075..d020992 100755
--- a/spec/unit/provider/exec/posix_spec.rb
+++ b/spec/unit/provider/exec/posix_spec.rb
@@ -57,13 +57,18 @@ describe provider_class do
           lambda { @provider.run("foo") }.should raise_error(ArgumentError, 
"'foo' is not executable")
         end
 
+        it "should not be able to execute shell builtins" do
+          @provider.resource[:path] = ['/bin']
+          lambda { @provider.run("cd ..") }.should raise_error(ArgumentError, 
"Could not find command 'cd'")
+        end
+
         it "should execute the command if the command given includes arguments 
or subcommands" do
           @provider.resource[:path] = ['/bogus/bin']
           File.stubs(:exists?).returns(false)
           File.stubs(:exists?).with("foo").returns(true)
           File.stubs(:executable?).with("foo").returns(true)
 
-          Puppet::Util.expects(:execute).with(['foo bar --sillyarg=true 
--blah'], {:uid => nil, :gid => nil, :combine => true, :failonfail => false})
+          Puppet::Util.expects(:execute).with() { |command, arguments| 
(command == ['foo bar --sillyarg=true --blah']) && (arguments.is_a? Hash) }
           @provider.run("foo bar --sillyarg=true --blah")
         end
 
@@ -80,7 +85,7 @@ describe provider_class do
           @provider.resource[:path] = ['/bogus/bin']
           File.stubs(:exists?).with("foo").returns(true)
           File.stubs(:executable?).with("foo").returns(true)
-          Puppet::Util.expects(:execute).with(['foo'], {:uid => nil, :gid => 
nil, :combine => true, :failonfail => false})
+          Puppet::Util.expects(:execute).with() { |command, arguments| 
(command == ['foo']) && (arguments.is_a? Hash) }
 
           @provider.run("foo")
         end
@@ -92,7 +97,7 @@ describe provider_class do
               File.stubs(:exists?).returns(false)
               
File.stubs(:exists?).with("/bogus/bin/foo#{extension}").returns(true)
               File.stubs(:executable?).with("foo").returns(true)
-              Puppet::Util.expects(:execute).with(['foo'], {:uid => nil, :gid 
=> nil, :combine => true, :failonfail => false})
+              Puppet::Util.expects(:execute).with() { |command, arguments| 
(command == ['foo']) && (arguments.is_a? Hash) }
 
               @provider.run("foo")
             end
@@ -105,7 +110,7 @@ describe provider_class do
           File.stubs(:exists?).with("foo").returns(true)
           File.stubs(:executable?).with("foo").returns(true)
 
-          Puppet::Util.expects(:execute).with(['foo'], {:uid => nil, :gid => 
nil, :combine => true, :failonfail => false})
+          Puppet::Util.expects(:execute).with() { |command, arguments| 
(command == ['foo']) && (arguments.is_a? Hash) }
           @provider.run("foo")
           @logs.map {|l| "#{l.level}: #{l.message}" }.should == ["warning: 
Overriding environment setting 'WHATEVER' with '/foo'"]
         end
diff --git a/spec/unit/provider/exec/shell_spec.rb 
b/spec/unit/provider/exec/shell_spec.rb
index 44390ff..a9b1f06 100644
--- a/spec/unit/provider/exec/shell_spec.rb
+++ b/spec/unit/provider/exec/shell_spec.rb
@@ -11,21 +11,27 @@ describe provider_class do
 
   describe "#run" do
     it "should be able to run builtin shell commands" do
-      output, status = @provider.run("echo foo")
+      output, status = @provider.run("if [ 1 == 1 ]; then echo 'blah'; fi")
       status.exitstatus.should == 0
-      output.should == "foo\n"
+      output.should == "blah\n"
     end
 
     it "should be able to run commands with single quotes in them" do
-      output, status = @provider.run("echo 'foo bar'")
+      output, status = @provider.run("echo 'foo  bar'")
       status.exitstatus.should == 0
-      output.should == "foo bar\n"
+      output.should == "foo  bar\n"
     end
 
     it "should be able to run commands with double quotes in them" do
-      output, status = @provider.run("echo 'foo bar'")
+      output, status = @provider.run('echo "foo  bar"')
       status.exitstatus.should == 0
-      output.should == "foo bar\n"
+      output.should == "foo  bar\n"
+    end
+
+    it "should be able to run multiple commands separated by a semicolon" do
+      output, status = @provider.run("echo 'foo' ; echo 'bar'")
+      status.exitstatus.should == 0
+      output.should == "foo\nbar\n"
     end
 
     it "should be able to read values from the environment parameter" do
-- 
1.7.4

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