Added test for sub su
authorHeiko Schlittermann (JUMPER) <hs@schlittermann.de>
Tue, 28 Jan 2014 14:03:04 +0100
changeset 40 d0410b54a231
parent 39 2721e331ea42
child 41 b761702df772
Added test for sub su
plugins/check_amanda-client
t/00-basic.t
--- a/plugins/check_amanda-client	Tue Jan 28 11:55:03 2014 +0100
+++ b/plugins/check_amanda-client	Tue Jan 28 14:03:04 2014 +0100
@@ -35,7 +35,15 @@
 sub verbose;
 sub unique { my %h; @h{@_} = (); keys %h }
 
-$SIG{__DIE__} = sub { UNKNOWN @_ unless $^S };
+local $SIG{__DIE__} = sub { UNKNOWN @_ unless $^S };
+
+# this we need for testing only, if this file gets
+# included as a module
+sub import {
+    no strict 'refs';
+    *{"$_[0]::verbose"} = sub { };
+}
+
 
 exit main @ARGV if not caller;
 
@@ -109,6 +117,10 @@
     $) = "@groups";
 
     verbose "su to $uid:$gid";
+
+    # during testing
+    return ($uid, $gid) if $ENV{HARNESS_ACTIVE};
+
     setgid $gid;
     setuid $uid;
 }
--- a/t/00-basic.t	Tue Jan 28 11:55:03 2014 +0100
+++ b/t/00-basic.t	Tue Jan 28 14:03:04 2014 +0100
@@ -7,6 +7,7 @@
 
 package FOO;
 ::require_ok 'blib/nagios/plugins/ius/check_amanda-client';
+FOO->import;
 
 package main;
 
@@ -55,4 +56,8 @@
 
 };
 
+subtest 'su' => sub {
+    is_deeply [FOO::su('root')], [0, 0], 'su to root';
+};
+
 done_testing;