summaryrefslogtreecommitdiffstats
path: root/t/Nagios-Plugin-Range.t
diff options
context:
space:
mode:
Diffstat (limited to 't/Nagios-Plugin-Range.t')
-rw-r--r--t/Nagios-Plugin-Range.t84
1 files changed, 84 insertions, 0 deletions
diff --git a/t/Nagios-Plugin-Range.t b/t/Nagios-Plugin-Range.t
new file mode 100644
index 0000000..13667de
--- /dev/null
+++ b/t/Nagios-Plugin-Range.t
@@ -0,0 +1,84 @@
1
2use strict;
3use Test::More tests => 60;
4BEGIN { use_ok('Nagios::Plugin::Range') };
5
6
7my $r = Nagios::Plugin::Range->parse_range_string("6");
8isa_ok( $r, "Nagios::Plugin::Range");
9ok( defined $r, "'6' is valid range");
10cmp_ok( $r->start, '==', 0, "Start correct");
11cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
12cmp_ok( $r->end, '==', 6, "End correct");
13cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity");
14cmp_ok( $r, 'eq', "6", "Stringification back to original");
15
16$r = Nagios::Plugin::Range->parse_range_string("-7:23");
17ok( defined $r, "'-7:23' is valid range");
18cmp_ok( $r->start, '==', -7, "Start correct");
19cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
20cmp_ok( $r->end, '==', 23, "End correct");
21cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity");
22cmp_ok( $r, 'eq', "-7:23", "Stringification back to original");
23
24$r = Nagios::Plugin::Range->parse_range_string(":5.75");
25ok( defined $r, "':5.75' is valid range");
26cmp_ok( $r->start, '==', 0, "Start correct");
27cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
28cmp_ok( $r->end, '==', 5.75, "End correct");
29cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity");
30cmp_ok( $r, 'eq', "5.75", "Stringification to simplification");
31
32$r = Nagios::Plugin::Range->parse_range_string("~:-95.99");
33ok( defined $r, "'~:-95.99' is valid range");
34cmp_ok( $r->start_infinity, '==', 1, "Using negative infinity");
35cmp_ok( $r->end, '==', -95.99, "End correct");
36cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity");
37cmp_ok( $r, 'eq', "~:-95.99", "Stringification back to original");
38
39$r = Nagios::Plugin::Range->parse_range_string("123456789012345:");
40ok( defined $r, "'123456789012345:' is valid range");
41cmp_ok( $r->start, '==', 123456789012345, "Start correct");
42cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
43cmp_ok( $r->end_infinity, '==', 1, "Using positive infinity");
44cmp_ok( $r, 'eq', "123456789012345:", "Stringification back to original");
45
46$r = Nagios::Plugin::Range->parse_range_string("~:0");
47ok( defined $r, "'~:0' is valid range");
48cmp_ok( $r->start_infinity, '==', 1, "Using negative infinity");
49cmp_ok( $r->end, '==', 0, "End correct");
50cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity");
51cmp_ok( $r->alert_on, '==', 0, "Will alert on outside of range");
52cmp_ok( $r, 'eq', "~:0", "Stringification back to original");
53ok( $r->check_range(0.5) == 1, "0.5 - alert");
54ok( $r->check_range(-10) == 0, "-10 - no alert");
55ok( $r->check_range(0) == 0, "0 - no alert");
56
57$r = Nagios::Plugin::Range->parse_range_string('@0:657.8210567');
58ok( defined $r, '"@0:657.8210567" is a valid range');
59cmp_ok( $r->start, '==', 0, "Start correct");
60cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
61cmp_ok( $r->end, '==', 657.8210567, "End correct");
62cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity");
63cmp_ok( $r->alert_on, '==', 1, "Will alert on inside of range");
64cmp_ok( $r, 'eq', '@657.8210567', "Stringification to simplified version");
65ok( $r->check_range(32.88) == 1, "32.88 - alert");
66ok( $r->check_range(-2) == 0, "-2 - no alert");
67ok( $r->check_range(657.8210567) == 1, "657.8210567 - alert");
68ok( $r->check_range(0) == 1, "0 - alert");
69
70$r = Nagios::Plugin::Range->parse_range_string('1:1');
71ok( defined $r, '"1:1" is a valid range');
72cmp_ok( $r->start, '==', 1, "Start correct");
73cmp_ok( $r->start_infinity, '==', 0, "Not using negative infinity");
74cmp_ok( $r->end, '==', 1, "End correct");
75cmp_ok( $r->end_infinity, '==', 0, "Not using positive infinity");
76cmp_ok( $r, 'eq', "1:1", "Stringification to simplified version");
77ok( $r->check_range(0.5) == 1, "0.5 - alert");
78ok( $r->check_range(1) == 0, "1 - no alert");
79ok( $r->check_range(5.2) == 1, "5.2 - alert");
80
81$r = Nagios::Plugin::Range->parse_range_string('2:1');
82ok( ! defined $r, '"2:1" is rejected');
83
84# TODO: Need more tests for invalid data