-
Notifications
You must be signed in to change notification settings - Fork 471
/
munin-run.t
53 lines (43 loc) · 1.3 KB
/
munin-run.t
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');
}