negate.pl 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #! /usr/bin/perl -w -I ..
  2. #
  3. # negate checks
  4. # Need check_dummy to work for testing
  5. #
  6. # $Id$
  7. #
  8. use strict;
  9. use Test::More;
  10. use NPTest;
  11. plan tests => 40;
  12. my $res;
  13. $res = NPTest->testCmd( "./negate" );
  14. is( $res->return_code, 3, "Not enough parameters");
  15. like( $res->output, "/Could not parse arguments/", "Could not parse arguments");
  16. $res = NPTest->testCmd( "./negate ./check_dummy 0 'a dummy okay'" );
  17. is( $res->return_code, 2, "OK changed to CRITICAL" );
  18. is( $res->output, "OK: a dummy okay" );
  19. $res = NPTest->testCmd( "./negate './check_dummy 0 redsweaterblog'");
  20. is( $res->return_code, 2, "OK => CRIT with a single quote for command to run" );
  21. is( $res->output, "OK: redsweaterblog" );
  22. $res = NPTest->testCmd( "./negate ./check_dummy 1 'a warn a day keeps the managers at bay'" );
  23. is( $res->return_code, 2, "WARN stays same" );
  24. $res = NPTest->testCmd( "./negate ./check_dummy 3 mysterious");
  25. is( $res->return_code, 3, "UNKNOWN stays same" );
  26. my %state = (
  27. ok => 0,
  28. warning => 1,
  29. critical => 2,
  30. unknown => 3,
  31. );
  32. foreach my $current_state (qw(ok warning critical unknown)) {
  33. foreach my $new_state (qw(ok warning critical unknown)) {
  34. $res = NPTest->testCmd( "./negate --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" );
  35. is( $res->return_code, $state{$new_state}, "Got fake $new_state" );
  36. is( $res->output, uc($current_state).": Fake $new_state" );
  37. }
  38. }