about summary refs log tree commit
path: root/t/nntp_compress.t
diff options
context:
space:
mode:
Diffstat (limited to 't/nntp_compress.t')
-rw-r--r--t/nntp_compress.t55
1 files changed, 55 insertions, 0 deletions
diff --git a/t/nntp_compress.t b/t/nntp_compress.t
new file mode 100644
index 0000000..7a0cc63
--- /dev/null
+++ b/t/nntp_compress.t
@@ -0,0 +1,55 @@
+#!perl
+# integration test for NNTP COMPRESS usage
+use 5.008001;
+use strict;
+use warnings;
+use Test::More;
+use Net::Config;
+use Net::NNTP;
+if (!eval { require Net::NNTP::Deflate }) {
+    plan skip_all => 'no DEFLATE support';
+}
+
+# tested on news.gmane.org, we can move it to nntp.lore.kernel.org if
+# gmane goes away since nntp.lore.kernel.org will likely start support
+# STARTTLS + COMPRESS soon
+my $host = $ENV{NNTP_COMPRESS_SERVER};
+unless($host && $NetConfig{test_hosts}) {
+    plan skip_all => 'NNTP_COMPRESS_SERVER not set';
+}
+
+plan tests => 16;
+
+# git 2.22.0 release announcement
+my $mid = '<xmqq36klozfu.fsf@gitster-ct.c.googlers.com>';
+my $orig;
+{
+  my $nntp = Net::NNTP->new($host);
+  ok($nntp, "opened connection to $host");
+  is($nntp->compression, undef, '->compression not active by default');
+  $orig = $nntp->article($mid);
+  ok($nntp->compress, '->compress successful');
+  is($nntp->compression, 'DEFLATE', '->compression active');
+  is_deeply($nntp->article($mid), $orig, 'got the same article after compress');
+
+  # check for misuse
+  is(eval { $nntp->starttls }, undef, '->starttls fails');
+  like($@, qr/DEFLATE/, '$@ mentions compression on ->starttls');
+  is(eval { $nntp->compress }, undef, '->compress fails again');
+  like($@, qr/DEFLATE/, '$@ mentions compression on ->compress');
+  ok($nntp->quit, 'QUIT OK');
+}
+
+SKIP: {
+  skip('no SSL support found in Net::NNTP', 6) if ! Net::NNTP->can_ssl;
+  my $nntp = Net::NNTP->new($host);
+  ok($nntp, "connected to $host again");
+  $orig ||= $nntp->article($mid);
+  ok($nntp->starttls, '->starttls works before ->compress');
+  ok($nntp->compress, '->compress works after ->starttls');
+  my $date = $nntp->date;
+  like($date, qr/[0-9]+/, 'DATE works');
+  is_deeply($nntp->article($mid), $orig,
+      'got the same article with both compress and starttls');
+  ok($nntp->quit, 'QUIT OK');
+}