summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/t/check_udp.t18
1 files changed, 15 insertions, 3 deletions
diff --git a/plugins/t/check_udp.t b/plugins/t/check_udp.t
index 6d24675..ae1718c 100644
--- a/plugins/t/check_udp.t
+++ b/plugins/t/check_udp.t
@@ -10,6 +10,8 @@ use NPTest;
10 10
11my $res; 11my $res;
12 12
13alarm(120); # make sure tests don't hang
14
13plan tests => 14; 15plan tests => 14;
14 16
15$res = NPTest->testCmd( "./check_udp -H localhost -p 3333" ); 17$res = NPTest->testCmd( "./check_udp -H localhost -p 3333" );
@@ -28,9 +30,17 @@ $res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -s foo -e bar" );
28cmp_ok( $res->return_code, '==', 2, "Errors correctly because no udp service running" ); 30cmp_ok( $res->return_code, '==', 2, "Errors correctly because no udp service running" );
29like ( $res->output, '/No data received from host/', "Output OK"); 31like ( $res->output, '/No data received from host/', "Output OK");
30 32
33my $nc;
34if(system("which netcat >/dev/null 2>&1") == 0) {
35 $nc = 'netcat -w 3 -l -u -p 3333';
36}
37elsif(system("which nc >/dev/null 2>&1") == 0) {
38 $nc = 'nc -w 3 -l -u -4 localhost 3333';
39}
40
31SKIP: { 41SKIP: {
32 skip "No netcat available", 6 unless (system("which nc > /dev/null") == 0); 42 skip "No netcat available", 6 unless $nc;
33 open (NC, "echo 'barbar' | nc -l -p 3333 -u |"); 43 open (NC, "echo 'barbar' | $nc |");
34 sleep 1; 44 sleep 1;
35 $res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -s '' -e barbar -4" ); 45 $res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -s '' -e barbar -4" );
36 cmp_ok( $res->return_code, '==', 0, "Got barbar response back" ); 46 cmp_ok( $res->return_code, '==', 0, "Got barbar response back" );
@@ -39,7 +49,7 @@ SKIP: {
39 49
40 # Start up a udp server listening on port 3333, quit after 3 seconds 50 # Start up a udp server listening on port 3333, quit after 3 seconds
41 # Otherwise will hang at close 51 # Otherwise will hang at close
42 my $pid = open(NC, "nc -l -p 3333 -u -w 3 </dev/null |"); 52 my $pid = open(NC, "$nc </dev/null |");
43 sleep 1; # Allow nc to startup 53 sleep 1; # Allow nc to startup
44 54
45 my $start = time; 55 my $start = time;
@@ -53,3 +63,5 @@ SKIP: {
53 cmp_ok( $read_nc, 'eq', "foofoo", "Data received correctly" ); 63 cmp_ok( $read_nc, 'eq', "foofoo", "Data received correctly" );
54} 64}
55 65
66
67alarm(0); # disable alarm