4
0

check_swap.t 1.2 KB

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