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