about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/lei-convert.t31
-rw-r--r--t/lei-import-nntp.t30
-rw-r--r--t/watch_nntp.t17
3 files changed, 54 insertions, 24 deletions
diff --git a/t/lei-convert.t b/t/lei-convert.t
index 29f8ba75..2ba62db3 100644
--- a/t/lei-convert.t
+++ b/t/lei-convert.t
@@ -6,26 +6,43 @@ use PublicInbox::MboxReader;
 use PublicInbox::MdirReader;
 use PublicInbox::NetReader;
 require_git 2.6;
-require_mods(qw(DBD::SQLite Search::Xapian Mail::IMAPClient));
+require_mods(qw(DBD::SQLite Search::Xapian Mail::IMAPClient Net::NNTP));
 my ($tmpdir, $for_destroy) = tmpdir;
 my $sock = tcp_server;
-my $cmd = [ '-imapd', '-W0', "--stdout=$tmpdir/1", "--stderr=$tmpdir/2" ];
+my $cmd = [ '-imapd', '-W0', "--stdout=$tmpdir/i1", "--stderr=$tmpdir/i2" ];
 my ($ro_home, $cfg_path) = setup_public_inboxes;
 my $env = { PI_CONFIG => $cfg_path };
-my $td = start_script($cmd, $env, { 3 => $sock }) or BAIL_OUT("-imapd: $?");
-my $host_port = tcp_host_port($sock);
+my $tdi = start_script($cmd, $env, { 3 => $sock }) or BAIL_OUT("-imapd: $?");
+my $imap_host_port = tcp_host_port($sock);
+$sock = tcp_server;
+$cmd = [ '-nntpd', '-W0', "--stdout=$tmpdir/n1", "--stderr=$tmpdir/n2" ];
+my $tdn = start_script($cmd, $env, { 3 => $sock }) or BAIL_OUT("-nntpd: $?");
+my $nntp_host_port = tcp_host_port($sock);
 undef $sock;
+
 test_lei({ tmpdir => $tmpdir }, sub {
         my $d = $ENV{HOME};
-        my $dig = Digest::SHA->new(256);
         lei_ok('convert', '-o', "mboxrd:$d/foo.mboxrd",
-                "imap://$host_port/t.v2.0");
-        ok(-f "$d/foo.mboxrd", 'mboxrd created');
+                "imap://$imap_host_port/t.v2.0");
+        ok(-f "$d/foo.mboxrd", 'mboxrd created from imap://');
+
+        lei_ok('convert', '-o', "mboxrd:$d/nntp.mboxrd",
+                "nntp://$nntp_host_port/t.v2");
+        ok(-f "$d/nntp.mboxrd", 'mboxrd created from nntp://');
+
         my (@mboxrd, @mboxcl2);
         open my $fh, '<', "$d/foo.mboxrd" or BAIL_OUT $!;
         PublicInbox::MboxReader->mboxrd($fh, sub { push @mboxrd, shift });
         ok(scalar(@mboxrd) > 1, 'got multiple messages');
 
+        open $fh, '<', "$d/nntp.mboxrd" or BAIL_OUT $!;
+        my $i = 0;
+        PublicInbox::MboxReader->mboxrd($fh, sub {
+                my ($eml) = @_;
+                is($eml->body, $mboxrd[$i]->body, "body matches #$i");
+                $i++;
+        });
+
         lei_ok('convert', '-o', "mboxcl2:$d/cl2", "mboxrd:$d/foo.mboxrd");
         ok(-s "$d/cl2", 'mboxcl2 non-empty') or diag $lei_err;
         open $fh, '<', "$d/cl2" or BAIL_OUT $!;
diff --git a/t/lei-import-nntp.t b/t/lei-import-nntp.t
new file mode 100644
index 00000000..3fb78fbc
--- /dev/null
+++ b/t/lei-import-nntp.t
@@ -0,0 +1,30 @@
+#!perl -w
+# Copyright (C) 2021 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use strict; use v5.10.1; use PublicInbox::TestCommon;
+require_git 2.6;
+require_mods(qw(json DBD::SQLite Search::Xapian Net::NNTP));
+my ($ro_home, $cfg_path) = setup_public_inboxes;
+my ($tmpdir, $for_destroy) = tmpdir;
+my $sock = tcp_server;
+my $cmd = [ '-nntpd', '-W0', "--stdout=$tmpdir/1", "--stderr=$tmpdir/2" ];
+my $env = { PI_CONFIG => $cfg_path };
+my $td = start_script($cmd, $env, { 3 => $sock }) or BAIL_OUT("-nntpd $?");
+my $host_port = tcp_host_port($sock);
+undef $sock;
+test_lei({ tmpdir => $tmpdir }, sub {
+        lei_ok(qw(q bytes:1..));
+        my $out = json_utf8->decode($lei_out);
+        is_deeply($out, [ undef ], 'nothing imported, yet');
+        lei_ok('import', "nntp://$host_port/t.v2");
+        diag $lei_err;
+        lei_ok(qw(q bytes:1..));
+        diag $lei_err;
+        $out = json_utf8->decode($lei_out);
+        ok(scalar(@$out) > 1, 'got imported messages');
+        is(pop @$out, undef, 'trailing JSON null element was null');
+        my %r;
+        for (@$out) { $r{ref($_)}++ }
+        is_deeply(\%r, { 'HASH' => scalar(@$out) }, 'all hashes');
+});
+done_testing;
diff --git a/t/watch_nntp.t b/t/watch_nntp.t
deleted file mode 100644
index c0ad3098..00000000
--- a/t/watch_nntp.t
+++ /dev/null
@@ -1,17 +0,0 @@
-# Copyright (C) 2020-2021 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 PublicInbox::Config;
-# see t/nntpd*.t for tests against a live NNTP server
-
-use_ok 'PublicInbox::Watch';
-my $nntp_url = \&PublicInbox::Watch::nntp_url;
-is('news://example.com/inbox.foo',
-        $nntp_url->('NEWS://examplE.com/inbox.foo'), 'lowercased');
-is('nntps://example.com/inbox.foo',
-        $nntp_url->('nntps://example.com/inbox.foo'), 'nntps:// accepted');
-is('nntps://example.com/inbox.foo',
-        $nntp_url->('SNEWS://example.com/inbox.foo'), 'snews => nntps');
-
-done_testing;