about summary refs log tree commit homepage
path: root/t/gzip_filter.t
diff options
context:
space:
mode:
Diffstat (limited to 't/gzip_filter.t')
-rw-r--r--t/gzip_filter.t37
1 files changed, 37 insertions, 0 deletions
diff --git a/t/gzip_filter.t b/t/gzip_filter.t
new file mode 100644
index 00000000..400214e6
--- /dev/null
+++ b/t/gzip_filter.t
@@ -0,0 +1,37 @@
+# Copyright (C) 2020 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use strict;
+use Test::More;
+use IO::Handle (); # autoflush
+use Fcntl qw(SEEK_SET);
+use PublicInbox::TestCommon;
+require_mods(qw(Compress::Zlib IO::Uncompress::Gunzip));
+require_ok 'PublicInbox::GzipFilter';
+
+{
+        open my $fh, '+>', undef or die "open: $!";
+        open my $dup, '>&', $fh or die "dup $!";
+        $dup->autoflush(1);
+        my $filter = PublicInbox::GzipFilter->new->attach($dup);
+        ok($filter->write("hello"), 'wrote something');
+        ok($filter->write("world"), 'wrote more');
+        $filter->close;
+        seek($fh, 0, SEEK_SET) or die;
+        IO::Uncompress::Gunzip::gunzip($fh => \(my $buf));
+        is($buf, 'helloworld', 'buffer matches');
+}
+
+{
+        pipe(my ($r, $w)) or die "pipe: $!";
+        $w->autoflush(1);
+        close $r or die;
+        my $filter = PublicInbox::GzipFilter->new->attach($w);
+        my $sigpipe;
+        local $SIG{PIPE} = sub { $sigpipe = 1 };
+        open my $fh, '<', 'COPYING' or die "open(COPYING): $!";
+        my $buf = do { local $/; <$fh> };
+        while ($filter->write($buf .= rand)) {}
+        ok($sigpipe, 'got SIGPIPE');
+        close $w;
+}
+done_testing;