check_swap.t 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. #! /usr/bin/perl -w -I ..
  2. #
  3. # Swap Space Tests via check_swap
  4. #
  5. # $Id$
  6. #
  7. use strict;
  8. use Test::More tests => 8;
  9. use NPTest;
  10. my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/';
  11. my $failureOutput = '/^SWAP CRITICAL - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/';
  12. my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+ MB out of [0-9]+ MB\)/';
  13. my $result;
  14. $result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576" ); # 1 MB free
  15. cmp_ok( $result->return_code, "==", 0, "At least 1MB free" );
  16. like( $result->output, $successOutput, "Right output" );
  17. $result = NPTest->testCmd( "./check_swap -w 1% -c 1%" ); # 1% free
  18. cmp_ok( $result->return_code, "==", 0, 'At least 1% free' );
  19. like( $result->output, $successOutput, "Right output" );
  20. $result = NPTest->testCmd( "./check_swap -w 100% -c 100%" ); # 100% (always critical)
  21. cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' );
  22. like( $result->output, $failureOutput, "Right output" );
  23. $result = NPTest->testCmd( "./check_swap -w 100% -c 1%" ); # 100% (always warn)
  24. cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' );
  25. like( $result->output, $warnOutput, "Right output" );