made remote timeout configurable by env
[scpubgit/System-Introspector.git] / t / sudoers.t
CommitLineData
478358f5 1use strictures 1;
2use Test::More;
3use FindBin;
4
afd7c030 5use System::Introspector::Probe::Sudoers;
478358f5 6
7my $dir = "$FindBin::Bin/sudoers-data";
8
9system("mkdir $dir");
10system("mkdir $dir/bar_host");
11
12my $start = write_file('sudoers',
13 'foo bar',
14 'baz qux',
15 "#include $dir/foo_%h",
16 "#includedir $dir/bar_%h",
17);
18
19my $foo_file = write_file('foo_host',
20 'in foo',
21);
22my $bar_file = write_file("bar_host/baz",
23 'in bar file',
24);
25
afd7c030 26my $probe = System::Introspector::Probe::Sudoers->new(
478358f5 27 sudoers_file => $start,
28 hostname => 'host',
29);
30
31ok((my $data = $probe->gather), 'received data');
32
33my $inc = "#include $dir/foo_\%h\n#includedir $dir/bar_\%h\n";
34is_deeply $data, {
35 $start => { body => "foo bar\nbaz qux\n$inc" },
36 $foo_file => { body => "in foo\n" },
37 $bar_file => { body => "in bar file\n" },
38}, 'found files';
39
40system("rm $_") for $start, $foo_file, $bar_file;
41system("rmdir $dir/bar_host");
42system("rmdir $dir");
43done_testing;
44
45sub write_file {
46 my ($file, @lines) = @_;
47 my $path = "$FindBin::Bin/sudoers-data/$file";
48 open my $fh, '>', $path or die "Unable to write $path: $!\n";
49 print $fh map "$_\n", @lines;
50 return $path;
51}