diff options
Diffstat (limited to 't/Nagios-Plugin-04.t')
-rw-r--r-- | t/Nagios-Plugin-04.t | 99 |
1 files changed, 0 insertions, 99 deletions
diff --git a/t/Nagios-Plugin-04.t b/t/Nagios-Plugin-04.t deleted file mode 100644 index e5eb3ab..0000000 --- a/t/Nagios-Plugin-04.t +++ /dev/null | |||
@@ -1,99 +0,0 @@ | |||
1 | |||
2 | # tests for toplevel access to Threshold and GetOpts stuff | ||
3 | |||
4 | use strict; | ||
5 | #use Test::More 'no_plan'; | ||
6 | use Test::More tests=>30; | ||
7 | |||
8 | BEGIN { use_ok('Nagios::Plugin') }; | ||
9 | use Nagios::Plugin::Functions; | ||
10 | Nagios::Plugin::Functions::_fake_exit(1); | ||
11 | |||
12 | |||
13 | eval { Nagios::Plugin->new(); }; | ||
14 | ok(! $@, "constructor DOESN'T die without usage"); | ||
15 | |||
16 | my $p = Nagios::Plugin->new(); | ||
17 | eval { $p->add_arg('warning', 'warning') }; | ||
18 | ok($@, "add_arg() dies if you haven't instantiated with usage"); | ||
19 | eval { $p->getopts }; | ||
20 | ok($@, "getopts() dies if you haven't instantiated with usage"); | ||
21 | |||
22 | $p = Nagios::Plugin->new( usage => "dummy usage statement" ); | ||
23 | |||
24 | # option accessors work | ||
25 | can_ok $p, 'opts'; | ||
26 | isa_ok $p->opts, 'Nagios::Plugin::Getopt', "Getopt object is defined"; | ||
27 | |||
28 | $p->add_arg('warning|w=s', "warning"); | ||
29 | $p->add_arg('critical|c=s', "critical"); | ||
30 | |||
31 | @ARGV = qw(-w 5 -c 10); | ||
32 | $p->getopts; | ||
33 | is $p->opts->warning, "5", "warning opt is accessible"; | ||
34 | is $p->opts->critical, "10", "critical opt is accessible"; | ||
35 | |||
36 | |||
37 | can_ok $p, 'perfdata'; | ||
38 | #isa_ok $p->perfdata, 'Nagios::Plugin::Performance', "perfdata object is defined"; | ||
39 | |||
40 | |||
41 | can_ok $p, 'threshold'; | ||
42 | #isa_ok $p->threshold, 'Nagios::Plugin::Threshold', "threshold object is defined"; | ||
43 | |||
44 | |||
45 | eval { $p->check_threshold() }; | ||
46 | ok($@, "check_threshold dies if called with no args"); | ||
47 | |||
48 | |||
49 | # thresholds set implicitly | ||
50 | is $p->check_threshold(2), OK, "check_threshold OK when called implicitly"; | ||
51 | is $p->check_threshold(6), WARNING, "check_threshold WARNING"; | ||
52 | is $p->check_threshold(11), CRITICAL, "check_threshold CRITICAL"; | ||
53 | is $p->check_threshold(check=>11), CRITICAL, "check_threshold CRITICAL with hash param"; | ||
54 | |||
55 | # Check that arrays allowed | ||
56 | is $p->check_threshold([2,1]), OK, "check_threshold OK when called implicitly"; | ||
57 | is $p->check_threshold([6,2]), WARNING, "check_threshold WARNING"; | ||
58 | is $p->check_threshold([1,2,6,11]), CRITICAL, "check_threshold CRITICAL"; | ||
59 | is $p->check_threshold(check=>[1,2,6,11]), CRITICAL, "check_threshold CRITICAL with hash param"; | ||
60 | |||
61 | # thresholds set explicitly | ||
62 | is $p->check_threshold( | ||
63 | check => 2, | ||
64 | warning => 50, | ||
65 | critical => 100 | ||
66 | ), OK, "check_threshold explicit OK"; | ||
67 | |||
68 | is $p->check_threshold( | ||
69 | check => 66, | ||
70 | warning => 50, | ||
71 | critical => 100 | ||
72 | ), WARNING, "check_threshold explicit WARNING"; | ||
73 | |||
74 | |||
75 | is $p->check_threshold( | ||
76 | check => -1, | ||
77 | warning => 5, | ||
78 | critical => '0:5', | ||
79 | ), CRITICAL, "check_threshold explicit CRITICAL"; | ||
80 | |||
81 | |||
82 | |||
83 | # what happens if you forget to define warning or critical thresholds? | ||
84 | $p = undef; | ||
85 | $p = Nagios::Plugin->new(); | ||
86 | |||
87 | is $p->check_threshold(2), UNKNOWN, "everything is now UNKNOWN"; | ||
88 | is $p->check_threshold(-200), UNKNOWN, "everything is now UNKNOWN"; | ||
89 | is $p->check_threshold(134098.3124), UNKNOWN, "everything is now UNKNOWN"; | ||
90 | is $p->check_threshold("foo bar baz"), UNKNOWN, "everything is now UNKNOWN"; | ||
91 | |||
92 | |||
93 | # how about when you define just one? | ||
94 | |||
95 | $p->set_thresholds(warning => "10:25"); | ||
96 | is $p->check_threshold(2), WARNING, "check_threshold works (WARNING) after explicit set_thresholds"; | ||
97 | is $p->check_threshold(-200), WARNING, "and again"; | ||
98 | is $p->check_threshold(25.5), WARNING, "and again"; | ||
99 | is $p->check_threshold(11), OK, "now OK"; | ||