diff options
Diffstat (limited to 't/lib.t')
-rw-r--r-- | t/lib.t | 50 |
1 files changed, 22 insertions, 28 deletions
@@ -1,6 +1,6 @@ # -*- Mode: cperl -*- -use Test::More tests => 46; +use Test::More tests => 40; use strict; use warnings; @@ -10,8 +10,7 @@ BEGIN { $tmpdir = "/tmp/spamcat.t.$$"; %conf = (dbpath => "$tmpdir/spamcat.sqlite3", default_count => 20, - deliver => "t/delivert $tmpdir", - domains => ['spamcat.example.com', 'spamcat2.example.com']); + domains => ['spamcat.example.com', 'spamcat2.example.com']); system("rm -rf $tmpdir") == 0 or die "Couldn't remove $tmpdir: $!\n"; @@ -58,13 +57,13 @@ is($addrs[0], 'baz@pham.com'); is($addrs[0], 'baz@pham.com'); is($addrs[1], 'one@two.com'); -ok(SpamCat->can('deliver'), 'Has delivery method'); -test_file('foo', 1); -test_file('foo2', 1); -test_file('multiple', 1); -test_file('wrongdomain', 1); -test_file('nosubj', 1); -test_file('bar', 0); +ok(SpamCat->can('filter'), 'Has filter method'); +test_file('foo'); +test_file('foo2'); +test_file('multiple'); +test_file('wrongdomain'); +test_file('nosubj'); +test_file('bar'); $sch->set_count('always-allowed', -1); test_file('always-allowed', 1); @@ -85,31 +84,26 @@ is($rows[4]->{sender}, 'nosubj'); is($rows[4]->{count}, 20); sub test_file { - my ($filen, $should_exist) = @_; + my ($filen) = @_; my $input = IO::File->new("<t/fixtures/$filen") || die "Couldn't open $filen: $!\n"; my $inputfd = fileno($input); open STDIN, ">&$inputfd" || die "Couldn't open $inputfd: $!\n"; + open STDOUT, ">$tmpdir/$filen" || die "Couldn't open $tmpdir/$filen: $!\n"; - $sch->deliver(); + $sch->filter(); - if ($should_exist) { - ok(-f "$tmpdir/$filen") || diag("$tmpdir/$filen doesn't exist."); + local $/; + my $fh = IO::File->new("<$tmpdir/$filen") || + die "Couldn't open $tmpdir/$filen for reading: $!\n"; + my $got = <$fh>; + $fh->close; - local $/; - my $fh = IO::File->new("<$tmpdir/$filen") || - die "Couldn't open $tmpdir/$filen for reading: $!\n"; - my $got = <$fh>; - $fh->close; + $fh = IO::File->new("<t/fixtures/$filen.expected") || + die "Couldn't open t/fixtures/$filen.expected for reading: $!\n"; + my $expected = <$fh>; + $fh->close; - $fh = IO::File->new("<t/fixtures/$filen.expected") || - die "Couldn't open t/fixtures/$filen.expected for reading: $!\n"; - my $expected = <$fh>; - $fh->close; - - is($got, $expected) || diag("Test for $filen output failed."); - } else { - ok(! -f "$tmpdir/$filen") || diag("$tmpdir/$filen exists."); - } + is($got, $expected) || diag("Test for $filen output failed."); } |