4
0

check_nt.t 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #! /usr/bin/perl -w -I ..
  2. #
  3. # Test check_nt by having a stub check_nt daemon
  4. #
  5. use strict;
  6. use Test::More;
  7. use NPTest;
  8. use FindBin qw($Bin);
  9. use IO::Socket;
  10. use IO::Select;
  11. use POSIX;
  12. my $port = 50000 + int(rand(1000));
  13. my $pid = fork();
  14. if ($pid) {
  15. # Parent
  16. #print "parent\n";
  17. # give our webserver some time to startup
  18. sleep(1);
  19. } else {
  20. # Child
  21. #print "child\n";
  22. my $server = IO::Socket::INET->new(
  23. LocalPort => $port,
  24. Type => SOCK_STREAM,
  25. Reuse => 1,
  26. Proto => "tcp",
  27. Listen => 10,
  28. ) or die "Cannot be a tcp server on port $port: $@";
  29. $server->autoflush(1);
  30. print "Please contact me at port $port\n";
  31. while (my $client = $server->accept ) {
  32. my $data = "";
  33. my $rv = $client->recv($data, POSIX::BUFSIZ, 0);
  34. my ($password, $command, $arg) = split('&', $data);
  35. if ($command eq "4") {
  36. if ($arg eq "c") {
  37. print $client "930000000&1000000000";
  38. } elsif ($arg eq "d") {
  39. print $client "UNKNOWN: Drive is not a fixed drive";
  40. }
  41. }
  42. }
  43. exit;
  44. }
  45. END { if ($pid) { print "Killing $pid\n"; kill "INT", $pid } };
  46. if ($ARGV[0] && $ARGV[0] eq "-d") {
  47. sleep 1000;
  48. }
  49. if (-x "./check_nt") {
  50. plan tests => 5;
  51. } else {
  52. plan skip_all => "No check_nt compiled";
  53. }
  54. my $result;
  55. my $command = "./check_nt -H 127.0.0.1 -p $port";
  56. $result = NPTest->testCmd( "$command -v USEDDISKSPACE -l c" );
  57. is( $result->return_code, 0, "USEDDISKSPACE c");
  58. is( $result->output, q{c:\ - total: 0.93 Gb - used: 0.07 Gb (7%) - free 0.87 Gb (93%) | 'c:\ Used Space'=0.07Gb;0.00;0.00;0.00;0.93}, "Output right" );
  59. $result = NPTest->testCmd( "$command -v USEDDISKSPACE -l d" );
  60. is( $result->return_code, 3, "USEDDISKSPACE d - invalid");
  61. is( $result->output, "Free disk space : Invalid drive", "Output right" );
  62. $result = NPTest->testCmd( "./check_nt -v USEDDISKSPACE -l d" );
  63. is( $result->return_code, 3, "Fail if -H missing");