summaryrefslogtreecommitdiffstats
path: root/web/attachments/112621-utils.pm.t
diff options
context:
space:
mode:
Diffstat (limited to 'web/attachments/112621-utils.pm.t')
-rw-r--r--web/attachments/112621-utils.pm.t141
1 files changed, 141 insertions, 0 deletions
diff --git a/web/attachments/112621-utils.pm.t b/web/attachments/112621-utils.pm.t
new file mode 100644
index 0000000..630985c
--- /dev/null
+++ b/web/attachments/112621-utils.pm.t
@@ -0,0 +1,141 @@
1#! /usr/bin/perl -w
2BEGIN {use File::Basename; use lib(dirname($0) . "/.."); }
3
4use strict;
5use Test::Simple tests => 80;
6use utils qw(&check_range);
7
8
9my @tests =
10(
11 # Format: [metric, range, name, expected result]
12 #
13 # 'Expected result' is the result expected from check_range: 0 if
14 # check_range should return 0 (metric is outside of range), 1 if
15 # check_range should return 1 (metric is inside range). The expected
16 # result can also be -1, indicating that check_range should exit with
17 # plugin error code of 'UNKNOWN' after a usage error (caused by an
18 # invalid range).
19
20 # Check min:max ranges
21 [-1, '2:4', 'Test 1', 0],
22 [0, '2:4', 'Test 2', 0],
23 [1, '2:4', 'Test 3', 0],
24 [2, '2:4', 'Test 4', 1],
25 [3, '2:4', 'Test 5', 1],
26 [4, '2:4', 'Test 6', 1],
27 [5, '2:4', 'Test 7', 0],
28
29 # Check max ranges
30 [-1, 2, 'Test 8', 0],
31 [0, 2, 'Test 9', 1],
32 [1, 2, 'Test 10', 1],
33 [2, 2, 'Test 11', 1],
34 [3, 2, 'Test 12', 0],
35
36 # Check :max ranges
37 [-1, ':2', 'Test 13', 0],
38 [0, ':2', 'Test 14', 1],
39 [1, ':2', 'Test 15', 1],
40 [2, ':2', 'Test 16', 1],
41 [3, ':2', 'Test 17', 0],
42 [-1, '1:', 'Test 18', 0],
43
44 # Check min: ranges
45 [0, '1:', 'Test 19', 0],
46 [1, '1:', 'Test 20', 1],
47 [2, '1:', 'Test 21', 1],
48
49 # Check 0
50 [-1, 0, 'Test 22', 0],
51 [0, 0, 'Test 23', 1],
52 [1, 0, 'Test 24', 1],
53
54 # Check ~:max ranges
55 [-1, '~:1', 'Test 25', 1],
56 [0, '~:1', 'Test 26', 1],
57 [1, '~:1', 'Test 27', 1],
58 [2, '~:1', 'Test 28', 0],
59
60 # Check min:max ranges where min and max are the same, including :0
61 # which should be equivalent to 0:0.
62 [-1, '1:1', 'Test 29', 0],
63 [0, '1:1', 'Test 30', 0],
64 [1, '1:1', 'Test 31', 1],
65 [2, '1:1', 'Test 32', 0],
66 [-1, '0:0', 'Test 33', 0],
67 [0, '0:0', 'Test 34', 1],
68 [1, '0:0', 'Test 35', 0],
69 [-1, ':0', 'Test 36', 0],
70 [0, ':0', 'Test 37', 1],
71 [1, ':0', 'Test 38', 0],
72
73 # Check min:max ranges which are invalid
74 [1, '4:2', 'Test 39', -1],
75 [1, '~:~', 'Test 40', -1],
76
77 # Check @min:max ranges
78 [-1, '@2:4', 'Test 1', 1],
79 [0, '@2:4', 'Test 2', 1],
80 [1, '@2:4', 'Test 3', 1],
81 [2, '@2:4', 'Test 4', 0],
82 [3, '@2:4', 'Test 5', 0],
83 [4, '@2:4', 'Test 6', 0],
84 [5, '@2:4', 'Test 7', 1],
85
86 # Check @max ranges
87 [-1, '@2', 'Test 8', 1],
88 [0, '@2', 'Test 9', 0],
89 [1, '@2', 'Test 10', 0],
90 [2, '@2', 'Test 11', 0],
91 [3, '@2', 'Test 12', 1],
92
93 # Check @:max ranges
94 [-1, '@:2', 'Test 13', 1],
95 [0, '@:2', 'Test 14', 0],
96 [1, '@:2', 'Test 15', 0],
97 [2, '@:2', 'Test 16', 0],
98 [3, '@:2', 'Test 17', 1],
99 [-1, '@1:', 'Test 18', 1],
100
101 # Check @min: ranges
102 [0, '@1:', 'Test 19', 1],
103 [1, '@1:', 'Test 20', 0],
104 [2, '@1:', 'Test 21', 0],
105
106 # Check @0
107 [-1, '@0', 'Test 22', 1],
108 [0, '@0', 'Test 23', 0],
109 [1, '@0', 'Test 24', 0],
110
111 # Check @~:max ranges
112 [-1, '@~:1', 'Test 25', 0],
113 [0, '@~:1', 'Test 26', 0],
114 [1, '@~:1', 'Test 27', 0],
115 [2, '@~:1', 'Test 28', 1],
116
117 # Check @min:max ranges where min and max are the same, including @:0
118 # which should be equivalent to @0:0.
119 [-1, '@1:1', 'Test 29', 1],
120 [0, '@1:1', 'Test 30', 1],
121 [1, '@1:1', 'Test 31', 0],
122 [2, '@1:1', 'Test 32', 1],
123 [-1, '@0:0', 'Test 33', 1],
124 [0, '@0:0', 'Test 34', 0],
125 [1, '@0:0', 'Test 35', 1],
126 [-1, '@:0', 'Test 36', 1],
127 [0, '@:0', 'Test 37', 0],
128 [1, '@:0', 'Test 38', 1],
129
130 # Check @min:max ranges which are invalid
131 [1, '@4:2', 'Test 39', -1],
132 [1, '@~:~', 'Test 40', -1],
133);
134
135foreach my $test (@tests)
136{
137 ok(check_range($test->[0], $test->[1]) == $test->[3],$test->[2]);
138}
139
140exit;
141