File: munin_node_configure_pluginlist.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 (92 lines) | stat: -rw-r--r-- 2,521 bytes parent folder | download | duplicates (12)
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
use strict;
use warnings;

use Test::More 'no_plan';

use_ok 'Munin::Node::Configure::PluginList';

use constant FOUND_DIRECTORY_SCRATCH => eval { require Directory::Scratch };


sub plugin_factory
{
    die 'Directory::Scratch not available' unless FOUND_DIRECTORY_SCRATCH;

    my $dir = Directory::Scratch->new();
    return sub {
        my ($name, @contents) = @_;
        my $plugin = $dir->touch($name, @contents);
        chmod(0755, $plugin->stringify);
        return Munin::Node::Configure::Plugin->new(
            path => $plugin->stringify,
            name => $plugin->basename,
        );
    };
}


### new
{
    my $pluginlist = new_ok('Munin::Node::Configure::PluginList' => [
        libdir     => '/usr/share/munin/plugins',
        servicedir => '/etc/munin/plugins/',
        families   => [ 'auto' ],
    ]) or next;

    is($pluginlist->{libdir},     '/usr/share/munin/plugins', 'libdir key exists');
    is($pluginlist->{servicedir}, '/etc/munin/plugins/',      'servicedir key exists');

    isa_ok($pluginlist->{library},  'Munin::Node::Service', 'libdir is inflated');
    isa_ok($pluginlist->{services}, 'Munin::Node::Service', 'servicedir is inflated');
}


### _valid_files
=cut
SKIP: {
    skip 'Directory::Scratch not installed' unless FOUND_DIRECTORY_SCRATCH;

    my $libdir = Directory::Scratch->new();
    my $valid = $libdir->touch('memory');
    chmod(0755, $valid->stringify);

    is(sprintf('%04o', $valid->stat->mode & 0777), '0755');

    my $invalid = $libdir->touch('if_');

    is_deeply([ Munin::Node::Configure::PluginList::_valid_files($libdir->base->stringify) ],
       [ { name => $valid->basename, path => $valid->stringify } ],
       'Found the only valid plugin');

    eval { Munin::Node::Configure::PluginList::_valid_files('/foo/blort/zork') };
    ok($@, 'Error on missing directory') or diag($@);
}
=cut


### list and names
=cut
SKIP: {
    skip 'Directory::Scratch not installed' unless FOUND_DIRECTORY_SCRATCH;

    my $plugins = Munin::Node::Configure::PluginList->new(
	libdir     => '/usr/share/munin/plugins',
	servicedir => '/etc/munin/plugins',
    );

    my $gen_plugin = plugin_factory;

    my @plugins = qw/memory if_ cpu/;

    for my $plugin (@plugins) {
	$plugins->{plugins}{$plugin} = $gen_plugin->($plugin);
    }

    is_deeply([ map { $_->{name} } $plugins->list ], [ sort @plugins ],
	      'List is sorted');

    is_deeply([ sort $plugins->names ], [ sort @plugins ], 'All plugin names are returned');
}
=cut

# vim: sw=4 : ts=4 : et