1 #! /usr/bin/perl -w -I ..
3 # Test check_nt by having a stub check_nt daemon
15 my $port = 50000 + int(rand(1000));
21 # give our webserver some time to startup
27 my $server = IO::Socket::INET->new(
33 ) or die "Cannot be a tcp server on port $port: $@";
35 $server->autoflush(1);
37 print "Please contact me at port $port\n";
38 while (my $client = $server->accept ) {
40 my $rv = $client->recv($data, POSIX::BUFSIZ, 0);
42 my ($password, $command, $arg) = split('&', $data);
44 if ($command eq "4") {
46 print $client "930000000&1000000000";
47 } elsif ($arg eq "d") {
48 print $client "UNKNOWN: Drive is not a fixed drive";
55 END { if ($pid) { print "Killing $pid\n"; kill "INT", $pid } };
57 if ($ARGV[0] && $ARGV[0] eq "-d") {
61 if (-x "./check_nt") {
64 plan skip_all => "No check_nt compiled";
68 my $command = "./check_nt -H 127.0.0.1 -p $port";
70 $result = NPTest->testCmd( "$command -v USEDDISKSPACE -l c" );
71 is( $result->return_code, 0, "USEDDISKSPACE c");
72 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" );
74 $result = NPTest
->testCmd( "$command -v USEDDISKSPACE -l d" );
75 is
( $result->return_code, 3, "USEDDISKSPACE d - invalid");
76 is
( $result->output, "Free disk space : Invalid drive", "Output right" );
78 $result = NPTest
->testCmd( "./check_nt -v USEDDISKSPACE -l d" );
79 is
( $result->return_code, 3, "Fail if -H missing");