1 #! /usr/bin/perl -w -I ..
3 # UDP Connection Based Tests via check_udp
16 $res = NPTest
->testCmd( "./check_udp2 -H localhost -p 3333" );
17 cmp_ok
( $res->return_code, '==', 3, "Need send/expect string");
18 like
( $res->output, '/With UDP checks, a send/expect string must be specified./', "Output OK");
20 $res = NPTest
->testCmd( "./check_udp2 -H localhost -p 3333 -s send" );
21 cmp_ok
( $res->return_code, '==', 3, "Need expect string");
22 like
( $res->output, '/With UDP checks, a send/expect string must be specified./', "Output OK");
24 $res = NPTest
->testCmd( "./check_udp2 -H localhost -p 3333 -e expect" );
25 cmp_ok
( $res->return_code, '==', 3, "Need send string");
26 like
( $res->output, '/With UDP checks, a send/expect string must be specified./', "Output OK");
28 $res = NPTest
->testCmd( "./check_udp2 -H localhost -p 3333 -s foo -e bar" );
29 cmp_ok
( $res->return_code, '==', 2, "Errors correctly because no udp service running" );
30 like
( $res->output, '/No data received from host/', "Output OK");
33 skip
"No netcat available", 6 unless (system("which nc > /dev/null") == 0);
34 open (NC
, "echo 'barbar' | nc -l -p 3333 -u |");
36 $res = NPTest
->testCmd( "./check_udp2 -H localhost -p 3333 -s '' -e barbar -4" );
37 cmp_ok
( $res->return_code, '==', 0, "Got barbar response back" );
38 like
( $res->output, '/\[barbar\]/', "Output OK");
41 # Start up a udp server listening on port 3333, quit after 3 seconds
42 # Otherwise will hang at close
43 my $pid = open(NC
, "nc -l -p 3333 -u -w 3 </dev/null |");
44 sleep 1; # Allow nc to startup
47 $res = NPTest
->testCmd( "./check_udp2 -H localhost -p 3333 -s foofoo -e barbar -t 5 -4" );
48 my $duration = time - $start;
49 cmp_ok
( $res->return_code, '==', '2', "Hung waiting for response");
50 like
( $res->output, '/Socket timeout after 5 seconds/', "Timeout message");
51 like
( $duration, '/^[56]$/', "Timeout after 5 (possibly 6) seconds");
54 cmp_ok
( $read_nc, 'eq', "foofoo", "Data received correctly" );