File: 32exported_function_interface.t

package info (click to toggle)
librrd-simple-perl 1.44-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,012 kB
  • ctags: 192
  • sloc: perl: 4,480; sh: 42; makefile: 3
file content (89 lines) | stat: -rw-r--r-- 1,913 bytes parent folder | download
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
# $Id: 32exported_function_interface.t 965 2007-03-01 19:11:23Z nicolaw $

chdir('t') if -d 't';
my $rrdfile = -d 't' ? 't/32test.rrd' : '32test.rrd';
unlink $rrdfile if -f $rrdfile;

use strict;

BEGIN {
	use Test::More;
	eval "use RRDs";
	plan skip_all => "RRDs.pm *MUST* be installed!" if $@;
	plan tests => 12 if !$@;
}

use lib qw(./lib ../lib);
use RRD::Simple 1.35 qw(:all);

use vars qw($rra %retention_periods %scheme_graphs @schemes %graph_return);
require 'answers.pl';

ok(create($rrdfile,
		bytesIn => 'GAUGE',
		bytesOut => 'GAUGE',
		faultsPerSec => 'COUNTER'
	),'create');

my $updated = time();
ok(update($rrdfile,
		bytesIn => 10039,
		bytesOut => 389,
		faultsPerSec => 0.4
	),'update');

ok(last_update($rrdfile) - $updated < 5 && last_update($rrdfile),
	'last_update');

ok(join(',',sort(sources($rrdfile))) eq 'bytesIn,bytesOut,faultsPerSec',
	'sources');

ok(my $period = retention_period($rrdfile),'retention_period');

my $default_period = $RRD::Simple::VERSION >= 1.33 ? 'mrtg' : 'year';
ok(abs($retention_periods{$default_period} - $period) < 1000,'retention_period result');

SKIP: {
	my $deep = 0;
	eval {
		require Test::Deep;
		Test::Deep->import();
		$deep = 1;
	};
	if (!$deep || $@) {
		skip 'Test::Deep not available', 1;
	}

	my $info = info($rrdfile);

	# The cur_row values appear to be random, so strip them out.
	for my $source (@{ $info->{rra} }) {
		delete $source->{cur_row};
	}

	cmp_deeply(
			$info->{rra},
			$rra,
			"info rra",
		);
}

(my $imgbasename = $rrdfile) =~ s/\.rrd$//;

ok(graph($rrdfile,destination => './'),'graph');

# By default we only have up to a year to graph
# for unless we specify the 3 year scheme, so
# dont bother checking for a 3years graph image.

for (qw(daily weekly monthly annual)) {
	my $img = "$imgbasename-$_.png";
	ok(-f $img,"$img");
	unlink $img if -f $img;
}

unlink $_ for glob('*.png');
unlink $rrdfile if -f $rrdfile;

1;