From f2820a509d91061b65fa32ec4e647cbd29760195 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Sun, 19 Jun 2022 19:55:38 -0400 Subject: Change to filter style from pipe. --- t/bin.t | 4 +--- t/conf.t | 3 +-- t/delivert | 25 ------------------------- t/fixtures/bar.expected | 15 +++++++++++++++ t/fixtures/sample.conf | 2 +- t/lib.t | 50 ++++++++++++++++++++++--------------------------- 6 files changed, 40 insertions(+), 59 deletions(-) delete mode 100755 t/delivert create mode 100644 t/fixtures/bar.expected (limited to 't') diff --git a/t/bin.t b/t/bin.t index 2c59e20..2bfb451 100755 --- a/t/bin.t +++ b/t/bin.t @@ -22,7 +22,6 @@ BEGIN { die "Couldn't create $tmpdir/spamcat.conf: $!\n"; print $fh "DBPATH = $tmpdir/spamcat.sqlite3\n"; print $fh "DEFAULT_COUNT = 20\n"; - print $fh "DELIVER = t/delivert $tmpdir\n"; print $fh "DOMAINS = spamcat.example.com\n"; } @@ -39,8 +38,7 @@ my @dumpconfig = `$spamcat -c $conffile dumpconfig`; my %got = parse_configdump(@dumpconfig); my %expected = (DBPATH => '/tmp/spamcat.sqlite3', DEFAULT_COUNT => 10, - DELIVER => 't/delivert', - DOMAINS => "spamcat.example.com, spamcat2.example.com, spamcat3"); + DOMAINS => "spamcat.example.com, spamcat2.example.com, spamcat3"); is_deeply(\%got, \%expected); # Unknown senders have the default number of mails left. diff --git a/t/conf.t b/t/conf.t index dbe2217..02a3095 100644 --- a/t/conf.t +++ b/t/conf.t @@ -1,6 +1,6 @@ # -*- mode: cperl -*- -use Test::More tests => 7; +use Test::More tests => 6; use strict; use warnings; @@ -13,6 +13,5 @@ ok(%conf); is($conf{dbpath}, '/tmp/spamcat.sqlite3'); is($conf{default_count}, 10); -is($conf{deliver}, 't/delivert'); is_deeply($conf{domains}, ['spamcat.example.com', 'spamcat2.example.com', 'spamcat3']); diff --git a/t/delivert b/t/delivert deleted file mode 100755 index 794e0a1..0000000 --- a/t/delivert +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env perl - -use Email::Simple; -use IO::File; - -use strict; -use warnings; - -die usage() unless $#ARGV == 0; -my $path = shift; - -local $/; -my $email = Email::Simple->new(<>); - -my $msgid = $email->header('Message-ID'); -$msgid =~ s/<(.*)@.*>/$1/; - -my $fh = IO::File->new(">$path/$msgid") || - die "Couldn't write to $path/$msgid: $!\n"; -print $fh $email->as_string; -$fh->close; - -sub usage { - "Usage: $0 path\n"; -} diff --git a/t/fixtures/bar.expected b/t/fixtures/bar.expected new file mode 100644 index 0000000..e554c65 --- /dev/null +++ b/t/fixtures/bar.expected @@ -0,0 +1,15 @@ +Return-Path: +Delivered-To: spamcat@example.com +Received: from mta.example.com + by mta.example.com (Dovecot) with LMTP id 9DDcI25oblTvgAEAQc1eRg + for ; Thu, 20 Nov 2014 17:17:18 -0500 +Received: by mta.example.com (Postfix, from userid 1001) + id 844956F1EE; Thu, 20 Nov 2014 17:17:18 -0500 (EST) +To: bar@spamcat.example.com +Subject: test - [21/20] +Message-Id: +Date: Thu, 20 Nov 2014 17:17:18 -0500 (EST) +From: sender@example.com (Spamcat Sender) +X-SpamCat-Remaining: 0 + +Sample email. diff --git a/t/fixtures/sample.conf b/t/fixtures/sample.conf index e0d644b..ba3054d 100644 --- a/t/fixtures/sample.conf +++ b/t/fixtures/sample.conf @@ -2,5 +2,5 @@ DBPATH=/tmp/spamcat.sqlite3 # So should most whitespace and inline comments. DEFAULT_COUNT =10 # Make sure key=val doesn't work in comments -DELIVER= t/delivert # by saying DEFAULT_COUNT=8 + # by saying DEFAULT_COUNT=8 DOMAINS = spamcat.example.com, spamcat2.example.com spamcat3 diff --git a/t/lib.t b/t/lib.t index 8afc46e..41b5704 100644 --- a/t/lib.t +++ b/t/lib.t @@ -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("&$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("; + $fh->close; - $fh = IO::File->new("; - $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."); } -- cgit v1.2.3