summaryrefslogtreecommitdiffstats
path: root/spec/unit/provider/exec
diff options
context:
space:
mode:
authorMax Martin <max@puppetlabs.com>2011-03-17 12:14:49 -0700
committerMax Martin <max@puppetlabs.com>2011-03-17 12:14:49 -0700
commitec1aa192825f17afbe4dc12be1e0f2d644d74155 (patch)
tree2cea3d2956e8d36711276edd31e968fbbb0eb618 /spec/unit/provider/exec
parent0d2d6f3f005ee99658ff86b79749f0ba7949beab (diff)
downloadpuppet-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
Diffstat (limited to 'spec/unit/provider/exec')
-rwxr-xr-xspec/unit/provider/exec/posix_spec.rb13
-rw-r--r--spec/unit/provider/exec/shell_spec.rb18
2 files changed, 21 insertions, 10 deletions
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