summaryrefslogtreecommitdiffstats
path: root/spec/unit/ral
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-11-19 16:03:21 -0600
committerLuke Kanies <luke@madstop.com>2007-11-19 16:03:21 -0600
commit0ac6b06ac171b2f8a307786ef0446625c3102d38 (patch)
tree42c94836f382052730bcd72b7ec4dd98ac5492a4 /spec/unit/ral
parent4bd7b6f69edfc984d153a23872a3ac6e123b5765 (diff)
parent1b78f57284a37e86db2351c34a2bbf22c43f0275 (diff)
downloadpuppet-0ac6b06ac171b2f8a307786ef0446625c3102d38.tar.gz
puppet-0ac6b06ac171b2f8a307786ef0446625c3102d38.tar.xz
puppet-0ac6b06ac171b2f8a307786ef0446625c3102d38.zip
Merge commit 'davids-bugfixes/rest/fix-903'
Diffstat (limited to 'spec/unit/ral')
-rwxr-xr-xspec/unit/ral/exec.rb124
1 files changed, 124 insertions, 0 deletions
diff --git a/spec/unit/ral/exec.rb b/spec/unit/ral/exec.rb
new file mode 100755
index 000000000..b465123f8
--- /dev/null
+++ b/spec/unit/ral/exec.rb
@@ -0,0 +1,124 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/type/exec'
+
+module ExecModuleTesting
+
+ def create_resource(command, output, exitstatus)
+ @user_name = 'some_user_name'
+ @group_name = 'some_group_name'
+ @execer = Puppet::Type.type(:exec).create(:name => command, :user => @user_name, :group => @group_name)
+
+ status = stub "process"
+ status.stubs(:exitstatus).returns(exitstatus)
+
+ 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
+ include ExecModuleTesting
+
+ it "should use the 'run_and_capture' method to exec" do
+ command = "/bin/true"
+ create_resource(command, "", 0)
+
+ @execer.refresh.should == :executed_command
+ end
+
+ it "should report a failure" do
+ command = "/bin/false"
+ create_resource(command, "", 1)
+
+ # 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
+
+ it "should log the output on success" do
+ #Puppet::Util::Log.newdestination :console
+ command = "/bin/false"
+ output = "output1\noutput2\n"
+ create_logging_resource(command, output, 0, true, :err)
+ expect_output(output, :err)
+ @execer.refresh
+ end
+
+ 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, 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
+ begin
+ @execer.refresh.should raise_error(Puppet::Error)
+ rescue Puppet::Error
+ raised = true
+ end
+ unless raised
+ 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
+