summaryrefslogtreecommitdiffstats
path: root/spec/unit
diff options
context:
space:
mode:
authorDavid Schmitt <david@schmitt.edv-bus.at>2007-11-19 10:21:56 +0100
committerDavid Schmitt <david@schmitt.edv-bus.at>2007-11-19 10:21:56 +0100
commit1b78f57284a37e86db2351c34a2bbf22c43f0275 (patch)
tree7d3c543c7c9879ffee7ef5c0d554d0ea880a2223 /spec/unit
parent4afbaa6f7042eb1cccc8938ee1ccb53c662ba41c (diff)
downloadpuppet-1b78f57284a37e86db2351c34a2bbf22c43f0275.tar.gz
puppet-1b78f57284a37e86db2351c34a2bbf22c43f0275.tar.xz
puppet-1b78f57284a37e86db2351c34a2bbf22c43f0275.zip
Add Exec{ logoutput=> on_failure }
This option only writes the output of the command to the log if the command failed.
Diffstat (limited to 'spec/unit')
-rwxr-xr-xspec/unit/ral/exec.rb64
1 files changed, 52 insertions, 12 deletions
diff --git a/spec/unit/ral/exec.rb b/spec/unit/ral/exec.rb
index b45b3e70b..b465123f8 100755
--- a/spec/unit/ral/exec.rb
+++ b/spec/unit/ral/exec.rb
@@ -16,6 +16,18 @@ module ExecModuleTesting
Puppet::Util::SUIDManager.expects(:run_and_capture).with([command], @user_name, @group_name).returns([output, status])
end
+
+ def create_logging_resource(command, output, exitstatus, logoutput, loglevel)
+ create_resource(command, output, exitstatus)
+ @execer[:logoutput] = logoutput
+ @execer[:loglevel] = loglevel
+ end
+
+ def expect_output(output, loglevel)
+ output.split(/\n/).each do |line|
+ @execer.property(:returns).expects(loglevel).with(line)
+ end
+ end
end
describe Puppet::Type::Exec, " when execing" do
@@ -48,13 +60,8 @@ describe Puppet::Type::Exec, " when execing" do
#Puppet::Util::Log.newdestination :console
command = "/bin/false"
output = "output1\noutput2\n"
- create_resource(command, output, 0)
- @execer[:logoutput] = true
- @execer[:loglevel] = :err
- output.split(/\n/).each do |line|
- @execer.property(:returns).expects(:err).with(line)
- end
-
+ create_logging_resource(command, output, 0, true, :err)
+ expect_output(output, :err)
@execer.refresh
end
@@ -62,12 +69,33 @@ describe Puppet::Type::Exec, " when execing" do
#Puppet::Util::Log.newdestination :console
command = "/bin/false"
output = "output1\noutput2\n"
- create_resource(command, output, 1)
- @execer[:logoutput] = true
- @execer[:loglevel] = :err
- output.split(/\n/).each do |line|
- @execer.property(:returns).expects(:err).with(line)
+ create_logging_resource(command, output, 1, true, :err)
+ expect_output(output, :err)
+
+ # no idea, why should raise_error doesn't work here
+ raised = false
+ begin
+ @execer.refresh.should raise_error(Puppet::Error)
+ rescue Puppet::Error
+ raised = true
+ end
+ unless raised
+ raise "didn't receive Puppet::Error"
end
+ end
+
+end
+
+
+describe Puppet::Type::Exec, " when logoutput=>on_failure is set," do
+ include ExecModuleTesting
+
+ it "should log the output on failure" do
+ #Puppet::Util::Log.newdestination :console
+ command = "/bin/false"
+ output = "output1\noutput2\n"
+ create_logging_resource(command, output, 1, :on_failure, :err)
+ expect_output(output, :err)
# no idea, why should raise_error doesn't work here
raised = false
@@ -80,5 +108,17 @@ describe Puppet::Type::Exec, " when execing" do
raise "didn't receive Puppet::Error"
end
end
+
+ it "shouldn't log the output on success" do
+ #Puppet::Util::Log.newdestination :console
+ command = "/bin/true"
+ output = "output1\noutput2\n"
+ create_logging_resource(command, output, 0, :on_failure, :err)
+ @execer.property(:returns).stubs(:err) do
+ fail "logging, where non was expected"
+ end
+ @execer.refresh
+ end
+
end