Debian Codegraph @

perl/t/Net-NSCAng-Client.t

raw
1 use strict;
2 use warnings;
3 use POSIX qw(setlocale LC_ALL);
4 use Test::More tests => 14;
5 use Test::Exception;
6 use Config;
7 use Net::NSCAng::Client;
8
9 BEGIN {
10 setlocale(LC_ALL, "C");
11 $Config{useithreads}
12 and warn "WARNING: Net::NSCAng::Client is not thread safe but your perl has threads enabled!\n";
13 };
14
15 my @cparams = qw/ localhost myid s3cr3t /;
16 my @nn = (node_name => 'here');
17 my @sd = (svc_description => 'bogus');
18 my $n;
19
20 lives_ok(sub { $n = Net::NSCAng::Client->new(@cparams) }, 'Simple constructor');
21 dies_ok(sub { $n->host_result(0, "OK") }, 'host_result() dies w/o node_name');
22 dies_ok(sub { $n->svc_result(0, "OK") }, 'svc_result() dies w/o node_name');
23 lives_ok(sub { crf(sub { $n->host_result(0, "OK", @nn) })}, 'host_result() with local node_name');
24 dies_ok(sub { $n->svc_result(0, "OK", @nn) }, 'svc_result() still dies with local node_name');
25
26 lives_ok(sub { $n = Net::NSCAng::Client->new(@cparams, @nn) }, 'Constructor with node_name');
27 lives_ok(sub {crf(sub { $n->host_result(0, "OK") })}, 'host_result() with node_name from constructor');
28 dies_ok(sub { $n->svc_result(0, "OK") }, 'svc_result() dies w/o svc_description');
29 lives_ok(sub {crf(sub { $n->svc_result(0, "OK", @sd) })}, 'svc_result() with local svc_description');
30
31 lives_ok(sub { $n = Net::NSCAng::Client->new(@cparams, @nn, @sd) }, 'Constructor with node_name');
32 lives_ok(sub { crf(sub { $n->host_result(0, "OK") })}, 'host_result() OK w/o local params');
33 lives_ok(sub { crf(sub { $n->svc_result(0, "OK") })}, 'svc_result() OK w/o local params');
34
35 dies_ok(sub { $n->command("BOGUS_COMMAND;1;2;3") }, 'command() dies w/o argument');
36 lives_ok(sub {crf(sub { $n->command("BOGUS_COMMAND;1;2;3") })}, 'command() works');
37 # Connection-refused-filter
38 # Supresses exceptions with a "connection refused" error as this is expected
39 sub crf {
40 my $sub = shift;
41 eval { $sub->() };
42 if($@) {
43 die $@ unless $@ =~ /SSL error:Connection refused/;
44 }
45 }