aboutsummaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2022-06-12 15:46:56 -0400
committerBrian Cully <bjc@kublai.com>2022-06-12 15:46:56 -0400
commitd5854dd65ddc3ab6638794b2554e7f86a358b89f (patch)
tree5f5e94f68e2c76c868398473a7fefb58b343d56d /t
parenta982d8ba8aa73bb316ebeb6f2eeabb304358b9fa (diff)
downloadspamcat-d5854dd65ddc3ab6638794b2554e7f86a358b89f.tar.gz
spamcat-d5854dd65ddc3ab6638794b2554e7f86a358b89f.zip
Add more tests, and fix setting count to 0.
Diffstat (limited to 't')
-rwxr-xr-xt/bin.t46
-rw-r--r--t/lib.t4
2 files changed, 43 insertions, 7 deletions
diff --git a/t/bin.t b/t/bin.t
index 5431242..2c59e20 100755
--- a/t/bin.t
+++ b/t/bin.t
@@ -1,12 +1,35 @@
#!/usr/bin/env perl
-use Test::More tests => 3;
+use Test::More tests => 9;
use IO::File;
use strict;
use warnings;
+my ($tmpdir, $tmpconf);
+BEGIN {
+ $tmpdir = "/tmp/spamcat.t.$$";
+ $tmpconf = "$tmpdir/spamcat.conf";
+
+ system("rm -rf $tmpdir") == 0
+ or die "Couldn't remove $tmpdir: $!\n";
+ mkdir $tmpdir;
+ system("sqlite3 $tmpdir/spamcat.sqlite3 < config/create-tables.sql") == 0
+ or die "Couldn't create $tmpdir/spamcat.sqlite3: $!\n";
+
+ my $fh = IO::File->new("> $tmpdir/spamcat.conf") ||
+ 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";
+}
+
+END {
+ system "rm -rf $tmpdir";
+}
+
my $spamcat = 'bin/spamcat';
my $conffile = 't/fixtures/sample.conf';
@@ -21,12 +44,25 @@ my %expected = (DBPATH => '/tmp/spamcat.sqlite3',
is_deeply(\%got, \%expected);
# Unknown senders have the default number of mails left.
-my @got = `$spamcat -c $conffile get unknown-sender`;
-is_deeply(\@got, ["unknown-sender has $expected{DEFAULT_COUNT} messages remaining.\n"]);
+my @got = `$spamcat -c $tmpconf get unknown-sender`;
+is_deeply(\@got, ["unknown-sender has 20 messages remaining.\n"]);
# Missing argument to set fails.
-my $got = system("$spamcat -c $conffile set missing-argument") >> 8;
-is_deeply($got, 1);
+my $got = system("$spamcat -c $tmpconf set missing-argument") >> 8;
+is($got, 1);
+
+# Can set/get remaining count.
+@got = `$spamcat -c $tmpconf set foo 1`;
+is($?, 0);
+is_deeply(\@got, ["foo has 1 messages remaining.\n"]);
+@got = `$spamcat -c $tmpconf get foo`;
+is_deeply(\@got, ["foo has 1 messages remaining.\n"]);
+
+@got = `$spamcat -c $tmpconf set foo 0`;
+is($?, 0);
+is_deeply(\@got, ["foo has 0 messages remaining.\n"]);
+@got = `$spamcat -c $tmpconf get foo`;
+is_deeply(\@got, ["foo has 0 messages remaining.\n"]);
sub parse_configdump {
my %rc;
diff --git a/t/lib.t b/t/lib.t
index b814c78..8afc46e 100644
--- a/t/lib.t
+++ b/t/lib.t
@@ -14,10 +14,10 @@ BEGIN {
domains => ['spamcat.example.com', 'spamcat2.example.com']);
system("rm -rf $tmpdir") == 0
- or die "Couldn't remove ‘$tmpdir’: $!\n";
+ or die "Couldn't remove $tmpdir: $!\n";
mkdir $tmpdir;
system("sqlite3 $conf{dbpath} < config/create-tables.sql") == 0
- or die "Couldn't create ‘$conf{dbpath}’: $!\n";
+ or die "Couldn't create $conf{dbpath}: $!\n";
}
END {