# HG changeset patch # User Heiko Schlittermann (JUMPER) # Date 1390914184 -3600 # Node ID d0410b54a231d6cc4262e8a15d5684f5770da5f0 # Parent 2721e331ea4254f2d57fbcc456d62fdbb7167b24 Added test for sub su diff -r 2721e331ea42 -r d0410b54a231 plugins/check_amanda-client --- 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; } diff -r 2721e331ea42 -r d0410b54a231 t/00-basic.t --- 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;