summaryrefslogtreecommitdiffstats
path: root/web/attachments/112621-utils.pm.t
blob: 630985cb0d7cba4054e0504e0edde41f4e93178a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#! /usr/bin/perl -w
BEGIN {use File::Basename; use lib(dirname($0) . "/.."); }

use strict;
use Test::Simple tests => 80;
use utils qw(&check_range);


my @tests =
(
  # Format: [metric, range, name, expected result]
  # 
  # 'Expected result' is the result expected from check_range: 0 if
  # check_range should return 0 (metric is outside of range), 1 if
  # check_range should return 1 (metric is inside range).  The expected
  # result can also be -1, indicating that check_range should exit with
  # plugin error code of 'UNKNOWN' after a usage error (caused by an
  # invalid range).

  # Check min:max ranges
  [-1, '2:4', 'Test 1', 0],
  [0, '2:4', 'Test 2', 0],
  [1, '2:4', 'Test 3', 0],
  [2, '2:4', 'Test 4', 1],
  [3, '2:4', 'Test 5', 1],
  [4, '2:4', 'Test 6', 1],
  [5, '2:4', 'Test 7', 0],
 
  # Check max ranges
  [-1, 2, 'Test 8', 0],
  [0, 2, 'Test 9', 1],
  [1, 2, 'Test 10', 1],
  [2, 2, 'Test 11', 1],
  [3, 2, 'Test 12', 0],
 
  # Check :max ranges
  [-1, ':2', 'Test 13', 0],
  [0, ':2', 'Test 14', 1],
  [1, ':2', 'Test 15', 1],
  [2, ':2', 'Test 16', 1],
  [3, ':2', 'Test 17', 0],
  [-1, '1:', 'Test 18', 0],
 
  # Check min: ranges
  [0, '1:', 'Test 19', 0],
  [1, '1:', 'Test 20', 1],
  [2, '1:', 'Test 21', 1],
 
  # Check 0
  [-1, 0, 'Test 22', 0],
  [0, 0, 'Test 23', 1],
  [1, 0, 'Test 24', 1],
 
  # Check ~:max ranges
  [-1, '~:1', 'Test 25', 1],
  [0, '~:1', 'Test 26', 1],
  [1, '~:1', 'Test 27', 1],
  [2, '~:1', 'Test 28', 0],
 
  # Check min:max ranges where min and max are the same, including :0
  # which should be equivalent to 0:0.
  [-1, '1:1', 'Test 29', 0],
  [0, '1:1', 'Test 30', 0],
  [1, '1:1', 'Test 31', 1],
  [2, '1:1', 'Test 32', 0],
  [-1, '0:0', 'Test 33', 0],
  [0, '0:0', 'Test 34', 1],
  [1, '0:0', 'Test 35', 0],
  [-1, ':0', 'Test 36', 0],
  [0, ':0', 'Test 37', 1],
  [1, ':0', 'Test 38', 0],
 
  # Check min:max ranges which are invalid
  [1, '4:2', 'Test 39', -1],
  [1, '~:~', 'Test 40', -1],

  # Check @min:max ranges
  [-1, '@2:4', 'Test 1', 1],
  [0, '@2:4', 'Test 2', 1],
  [1, '@2:4', 'Test 3', 1],
  [2, '@2:4', 'Test 4', 0],
  [3, '@2:4', 'Test 5', 0],
  [4, '@2:4', 'Test 6', 0],
  [5, '@2:4', 'Test 7', 1],
 
  # Check @max ranges
  [-1, '@2', 'Test 8', 1],
  [0, '@2', 'Test 9', 0],
  [1, '@2', 'Test 10', 0],
  [2, '@2', 'Test 11', 0],
  [3, '@2', 'Test 12', 1],
 
  # Check @:max ranges
  [-1, '@:2', 'Test 13', 1],
  [0, '@:2', 'Test 14', 0],
  [1, '@:2', 'Test 15', 0],
  [2, '@:2', 'Test 16', 0],
  [3, '@:2', 'Test 17', 1],
  [-1, '@1:', 'Test 18', 1],
 
  # Check @min: ranges
  [0, '@1:', 'Test 19', 1],
  [1, '@1:', 'Test 20', 0],
  [2, '@1:', 'Test 21', 0],
 
  # Check @0
  [-1, '@0', 'Test 22', 1],
  [0, '@0', 'Test 23', 0],
  [1, '@0', 'Test 24', 0],
 
  # Check @~:max ranges
  [-1, '@~:1', 'Test 25', 0],
  [0, '@~:1', 'Test 26', 0],
  [1, '@~:1', 'Test 27', 0],
  [2, '@~:1', 'Test 28', 1],
 
  # Check @min:max ranges where min and max are the same, including @:0
  # which should be equivalent to @0:0.
  [-1, '@1:1', 'Test 29', 1],
  [0, '@1:1', 'Test 30', 1],
  [1, '@1:1', 'Test 31', 0],
  [2, '@1:1', 'Test 32', 1],
  [-1, '@0:0', 'Test 33', 1],
  [0, '@0:0', 'Test 34', 0],
  [1, '@0:0', 'Test 35', 1],
  [-1, '@:0', 'Test 36', 1],
  [0, '@:0', 'Test 37', 0],
  [1, '@:0', 'Test 38', 1],
 
  # Check @min:max ranges which are invalid
  [1, '@4:2', 'Test 39', -1],
  [1, '@~:~', 'Test 40', -1],
);

foreach my $test (@tests)
{
  ok(check_range($test->[0], $test->[1]) == $test->[3],$test->[2]);
}

exit;