1use strict;
2use Test::More tests => 8;
3
4use File::Scan::ClamAV;
5use Cwd;
6
7do "t/mkconf.pl";
8
9# start clamd
10my $pid = fork;
11die "Fork failed" unless defined $pid;
12if (!$pid) {
13    exec "$ENV{CLAMD_PATH}/clamd -c clamav.conf";
14    die "clamd failed to start: $!";
15}
16for (1..120) {
17  last if (-e "clamsock");
18  if (kill(0 => $pid) == 0) {
19    die "clamd appears to have died";
20  }
21  sleep(1);
22}
23
24my $av = new File::Scan::ClamAV(port => "clamsock", find_all => 1);
25ok($av, "Init ok");
26
27my $dir = cwd;
28ok($dir, "cd ok");
29
30my $testdir = "$dir/testfiles";
31ok(-d $testdir, "Dir exits");
32print "# Scanning $testdir\n";
33my %results = $av->scan($testdir);
34
35print "# Results: ", (map { "$_ => $results{$_}, " } keys(%results)), "\n";
36ok(exists($results{"$testdir/clamavtest"}), "Didn't detect $testdir/clamavtest");
37ok(exists($results{"$testdir/clamavtest.zip"}), "Didn't detect $testdir/clamavtest.zip");
38ok(exists($results{"$testdir/clamavtest.gz"}), "Didn't detect $testdir/clamavtest.gz");
39ok(!exists($results{"$testdir/innocent"}), "Accidentally detected $testdir/innocent file");
40
41ok(kill(9 => $pid), "Kill ok");
42waitpid($pid, 0);
43unlink("clamsock");
44
45