diff options
author | Max Martin <max@puppetlabs.com> | 2011-03-17 12:14:49 -0700 |
---|---|---|
committer | Max Martin <max@puppetlabs.com> | 2011-03-17 12:14:49 -0700 |
commit | ec1aa192825f17afbe4dc12be1e0f2d644d74155 (patch) | |
tree | 2cea3d2956e8d36711276edd31e968fbbb0eb618 | |
parent | 0d2d6f3f005ee99658ff86b79749f0ba7949beab (diff) | |
download | puppet-ec1aa192825f17afbe4dc12be1e0f2d644d74155.tar.gz puppet-ec1aa192825f17afbe4dc12be1e0f2d644d74155.tar.xz puppet-ec1aa192825f17afbe4dc12be1e0f2d644d74155.zip |
(#4884) Revise new exec tests, add a few more
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
-rwxr-xr-x | lib/puppet/type/exec.rb | 2 | ||||
-rwxr-xr-x | spec/unit/provider/exec/posix_spec.rb | 13 | ||||
-rw-r--r-- | 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 67d40a7cc..4458bf081 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 a9b207533..d02099250 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 44390ff08..a9b1f06ba 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 |