File: munin_plugin.t

package info (click to toggle)
munin 2.0.76-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,068 kB
  • sloc: perl: 11,684; java: 1,924; sh: 1,632; makefile: 636; javascript: 365; python: 267
file content (71 lines) | stat: -rw-r--r-- 2,906 bytes parent folder | download | duplicates (14)
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
use warnings;
use strict;

use Test::More tests => 37;

use_ok('Munin::Plugin');

### clean_fieldname
my $valid = qr/^[A-Za-z_][A-Za-z0-9_]+$/;

# good
like(clean_fieldname('abcDEF123'), $valid);
# start with bad characters
like(clean_fieldname('1bcde'), $valid);
like(clean_fieldname('!bcde'), $valid);
# bad characters throughout
like(clean_fieldname('/abc/def'), $valid);


### _{encode,decode}_string
my @strings = (
	'abcde',
	'abc123DEF',
	"1234\n1234",
	'12% of my dinner',
	"\0\x{263a}",
);

is(Munin::Plugin::_decode_string(Munin::Plugin::_encode_string($_)),
	$_, 'string encode -> decode round-trip') foreach (@strings);


### _{encode,decode}_state
is_deeply(
	[ Munin::Plugin::_decode_state(Munin::Plugin::_encode_state(@strings)) ],
	\@strings,
	'state encode -> decode round-trip'
);


### scaleNumber

is(scaleNumber(1000000000000000000000000000000000,"bps","no "),     '1000000000.0Ybps');
is(scaleNumber(1000000000000000000000000000000,"bps","no "),        '1000000.0Ybps');
is(scaleNumber(1000000000000000000000000000,"bps","no "),           '1000.0Ybps');
is(scaleNumber(1000000000000000000000000,"bps","no "),              '1.0Ybps');
is(scaleNumber(1000000000000000000000,"bps","no "),                 '1.0Zbps');
is(scaleNumber(1000000000000000000,"bps","no "),                    '1.0Ebps');
is(scaleNumber(1000000000000000,"bps","no "),                       '1.0Pbps');
is(scaleNumber(1000000000000,"bps","no "),                          '1.0Tbps');
is(scaleNumber(1000000000,"bps","no "),                             '1.0Gbps');
is(scaleNumber(1000000,"bps","no "),                                '1.0Mbps');
is(scaleNumber(1000,"bps","no "),                                   '1.0kbps');
is(scaleNumber(1,"bps","no "),                                      '1.0bps');
is(scaleNumber(0.9999,"bps","no "),                                 '999.9mbps');
is(scaleNumber(0.1,"bps","no "),                                    '100.0mbps');
is(scaleNumber(0.001,"bps","no "),                                  '1.0mbps');
is(scaleNumber(0.000001,"bps","no "),                               '1.0ubps');
is(scaleNumber(0.000000001,"bps","no "),                            '1.0nbps');
is(scaleNumber(0.000000000001,"bps","no "),                         '1.0pbps');
is(scaleNumber(0.000000000000001,"bps","no "),                      '1.0fbps');
is(scaleNumber(0.000000000000000001,"bps","no "),                   '1.0abps');
is(scaleNumber(0.000000000000000000001,"bps","no "),                '1.0zbps');
is(scaleNumber(0.000000000000000000000001,"bps","no "),             '1.0ybps');
is(scaleNumber(0.000000000000000000000000001,"bps","no "),          'no ');
is(scaleNumber(0.000000000000000000000000000001,"bps","no "),       'no ');
is(scaleNumber(0.000000000000000000000000000000001,"bps","no "),    'no ');
is(scaleNumber(0.000000000000000000000000000000000001,"bps","no "), 'no ');