1use strict;
2use warnings;
3
4use Test::More tests => 7;
5
6use File::Temp qw( tempfile );
7use Munin::Node::Configure::Plugin;
8
9use_ok 'Munin::Node::Configure::History';
10
11my ($fh, $history_file) = tempfile( UNLINK => 1);
12
13print {$fh} <<'EOH';
14#
15# This file contains a test plugin history.
16#
17
18[0.0.0]
19[0.9.2]
20[0.9.7]
21
22[0.9.8]
23df
24df_inode
25freebsd/df_inode
26freebsd/open_files
27linux/cpu
28
29[0.9.9pre1]
30[0.9.9pre2]
31squid_cache
32tomcat_volume
33[1.3.3]
34users
35[1.3.4]
36  colour_tester
37squid_objectsize
38
39EOH
40
41close $fh;
42
43
44### tests start here ###########################################################
45
46### new
47{
48    new_ok('Munin::Node::Configure::History' => [
49	history_file => '/usr/share/munin/plugins/plugins.history',
50    ]);
51}
52{
53    eval { Munin::Node::Configure::History->new(newer => '1.2.3') };
54    like($@, qr/history/, 'Error if no history file is specified');
55}
56
57
58### load
59{
60    # no history file
61    my $hist = Munin::Node::Configure::History->new(
62	history_file => '/foo/blort',
63	newer  => '1.3.4',
64    );
65    eval { $hist->load };
66    ok($@, 'Dies if history file is non-existent');
67}
68{
69    my $hist = Munin::Node::Configure::History->new(
70	history_file => '/foo/blort',
71    );
72    eval { $hist->load };
73    unlike($@, qr/./, 'File is not read when --newer was not specified');
74}
75{
76    my $hist = Munin::Node::Configure::History->new(
77	history_file => $history_file,
78	newer  => '1.3.3',
79    );
80    $hist->load;
81
82    is_deeply(
83    	[ sort keys %{$hist->{valid_plugins}} ],
84	[qw/colour_tester squid_objectsize/],
85	'Got the right plugins'
86    );
87}
88{
89    my $hist = Munin::Node::Configure::History->new(
90	history_file => $history_file,
91	newer  => '31.3.3',
92    );
93    eval { $hist->load };
94    ok($@, 'Dies with invalid version number.');
95}
96
97# TODO: test platform-detection
98
99
100### too_old
101
102
103
104