X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Flei-convert.t;h=20099f65b89c7be6c5d1bb56f1be048b76873225;hb=9d1d7c2b505454fba331666a951e0f7997500b3c;hp=29f8ba755d0410903a603c7a16bc5042f964c211;hpb=fc69b9b91323c62e8abeaa8723f4d3fffdac0e27;p=public-inbox.git diff --git a/t/lei-convert.t b/t/lei-convert.t index 29f8ba75..20099f65 100644 --- a/t/lei-convert.t +++ b/t/lei-convert.t @@ -5,27 +5,45 @@ use strict; use v5.10.1; use PublicInbox::TestCommon; use PublicInbox::MboxReader; use PublicInbox::MdirReader; use PublicInbox::NetReader; +use PublicInbox::Eml; 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 $!; @@ -67,5 +85,19 @@ test_lei({ tmpdir => $tmpdir }, sub { open $fh, '<', "$d/foo.mboxrd" or BAIL_OUT; my $exp = do { local $/; <$fh> }; is($out, $exp, 'stdin => stdout'); + + lei_ok qw(convert -F eml -o mboxcl2:/dev/stdout t/plack-qp.eml); + open $fh, '<', \$lei_out or BAIL_OUT; + @bar = (); + PublicInbox::MboxReader->mboxcl2($fh, sub { + my $eml = shift; + for my $h (qw(Status Content-Length Lines)) { + ok(defined($eml->header_raw($h)), + "$h defined for mboxcl2"); + $eml->header_set($h); + } + push @bar, $eml; + }); + is_deeply(\@bar, [ eml_load('t/plack-qp.eml') ], 'eml => mboxcl2'); }); done_testing;