File: munin-run.t

package info (click to toggle)
munin 2.0.25-1%2Bdeb8u3~bpo70%2B1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy-backports
  • size: 6,184 kB
  • sloc: perl: 11,818; sh: 3,545; java: 1,880; makefile: 767; python: 272
file content (53 lines) | stat: -rw-r--r-- 1,334 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
use Test::More tests => 6;
use strict;

my $PREFIX = $ENV{PWD}.'/t/install';
my $run    = "$PREFIX/sbin/munin-run --sconfdir=$ENV{PWD}/t/plugin-conf.d";

sub run {
    my $plugin = shift or die "run(): plugin required\n";

    my @lines = `$run $plugin` or warn "No output from '$plugin' plugin\n";
    warn "Error running '$plugin' plugin\n", @lines if $?;

    my %ret;
    for (@lines) {
	if (/^(\w+)\.(\w+)\s+(.+)/) { # unfuck cperl-mode +
	    $ret{$1}{$2} = $3;
	}
	elsif (/(\w+)\s+(.+)/) {
	    $ret{$1} = $2;
	}
    }
    return %ret;
}

SKIP: {
    skip "need root for uid/gid tests", 4 if $>;
    skip "nobody/nogroup missing", 4
      unless getpwnam('nobody') && getgrnam('nogroup');

    my %id = run('id_default');
    is($id{uid}{extinfo}, 'nobody', "default user");
    like($id{gid}{extinfo}, qr/^nogroup/, "default group");
    
    my %id = run('id_root');
    is($id{uid}{value}, 0, 'user override');
    like($id{gid}{extinfo}, qr/\broot\b/, 'group override');
}

my %env = run('env');
is_deeply(\%env,
	  { count      => { value   => 1 },
	    munin_test => { value   => 4,
			    extinfo => 'test',
			  },
	  },
	  'environment variables');

TODO: {
    local $TODO = "munin-run doesn't handle this";

    my %config = run('env config');
    is($config{host_name}, 'test.example.com', 'host_name override');
}