aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2022-06-12 14:54:03 -0400
committerBrian Cully <bjc@kublai.com>2022-06-12 14:54:03 -0400
commit575c0485c4939922bab313da666a8a18d80c065e (patch)
tree628c6fbebe80e821704d6d4eb9497dc28a657dc8
parent5a61fd826df757d585966795936058e5136e7414 (diff)
downloadspamcat-575c0485c4939922bab313da666a8a18d80c065e.tar.gz
spamcat-575c0485c4939922bab313da666a8a18d80c065e.zip
Return default email count for unknown senders on CLI.
-rwxr-xr-xbin/spamcat2
-rwxr-xr-x[-rw-r--r--]t/bin.t15
2 files changed, 10 insertions, 7 deletions
diff --git a/bin/spamcat b/bin/spamcat
index 8549d95..25f04d2 100755
--- a/bin/spamcat
+++ b/bin/spamcat
@@ -94,7 +94,7 @@ if ($#ARGV >= 0) {
} elsif ($cmd eq 'get') {
my $sender = shift @ARGV;
pod2usage(1) unless $sender;
- my $count = $sch->get_count($sender);
+ my $count = $sch->get_count($sender) || $conf{default_count};
print "$sender has $count messages remaining.\n";
} elsif ($cmd eq 'set') {
my ($sender, $count) = @ARGV;
diff --git a/t/bin.t b/t/bin.t
index b27e994..5431242 100644..100755
--- a/t/bin.t
+++ b/t/bin.t
@@ -1,6 +1,6 @@
#!/usr/bin/env perl
-use Test::More tests => 1;
+use Test::More tests => 3;
use IO::File;
@@ -12,7 +12,7 @@ my $conffile = 't/fixtures/sample.conf';
# Add testlib which has createdb and possibly population of said db.
-my @dumpconfig = `$spamcat -c t/fixtures/sample.conf dumpconfig`;
+my @dumpconfig = `$spamcat -c $conffile dumpconfig`;
my %got = parse_configdump(@dumpconfig);
my %expected = (DBPATH => '/tmp/spamcat.sqlite3',
DEFAULT_COUNT => 10,
@@ -20,10 +20,13 @@ my %expected = (DBPATH => '/tmp/spamcat.sqlite3',
DOMAINS => "spamcat.example.com, spamcat2.example.com, spamcat3");
is_deeply(\%got, \%expected);
-# TODO: Test for proper exit codes.
-#my $fh = IO::File->new("|$spamcat -c $conffile") ||
-# die "Couldn't open pipe to $spamcat: $!\n";
-#$fh->close;
+# 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"]);
+
+# Missing argument to set fails.
+my $got = system("$spamcat -c $conffile set missing-argument") >> 8;
+is_deeply($got, 1);
sub parse_configdump {
my %rc;