Fix for SSL Versioning when multiple options are used.
[monitoring-plugins.git] / plugins / tests / check_nt.t
blob223d4933815ef1b65cd5b9df374ae6fa93db89c6
1 #! /usr/bin/perl -w -I ..
3 # Test check_nt by having a stub check_nt daemon
6 use strict;
7 use Test::More;
8 use NPTest;
9 use FindBin qw($Bin);
11 use IO::Socket;
12 use IO::Select;
13 use POSIX;
15 my $port = 50000 + int(rand(1000));
17 my $pid = fork();
18 if ($pid) {
19 # Parent
20 #print "parent\n";
21 # give our webserver some time to startup
22 sleep(1);
23 } else {
24 # Child
25 #print "child\n";
27 my $server = IO::Socket::INET->new(
28 LocalPort => $port,
29 Type => SOCK_STREAM,
30 Reuse => 1,
31 Proto => "tcp",
32 Listen => 10,
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 ) {
39 my $data = "";
40 my $rv = $client->recv($data, POSIX::BUFSIZ, 0);
42 my ($password, $command, $arg) = split('&', $data);
44 if ($command eq "4") {
45 if ($arg eq "c") {
46 print $client "930000000&1000000000";
47 } elsif ($arg eq "d") {
48 print $client "UNKNOWN: Drive is not a fixed drive";
52 exit;
55 END { if ($pid) { print "Killing $pid\n"; kill "INT", $pid } };
57 if ($ARGV[0] && $ARGV[0] eq "-d") {
58 sleep 1000;
61 if (-x "./check_nt") {
62 plan tests => 5;
63 } else {
64 plan skip_all => "No check_nt compiled";
67 my $result;
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");