]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/lei-import-nntp.t
net_reader: fix single NNTP article fetch, test ranges
[public-inbox.git] / t / lei-import-nntp.t
index 3fb78fbcb9d27c995f02f58b654ac40142f1428d..1eb41e0ed2f9425d60333c46792f8781ba5a031a 100644 (file)
@@ -13,18 +13,55 @@ 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..));
+       lei_ok(qw(q z: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;
+       my $url = "nntp://$host_port/t.v2";
+       lei_ok(qw(ls-mail-source), "nntp://$host_port/");
+       like($lei_out, qr/^t\.v2$/ms, 'shows newsgroup');
+       lei_ok(qw(ls-mail-source), $url);
+       is($lei_out, "t.v2\n", 'shows only newsgroup with filter');
+       lei_ok(qw(ls-mail-source -l), "nntp://$host_port/");
+       is(ref(json_utf8->decode($lei_out)), 'ARRAY', 'ls-mail-source JSON');
+
+       lei_ok('import', $url);
+       lei_ok(qw(q z:1..));
        $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');
+
+       my $f = "$ENV{HOME}/.local/share/lei/store/mail_sync.sqlite3";
+       ok(-s $f, 'mail_sync exists tracked for redundant imports');
+       lei_ok 'ls-mail-sync';
+       like($lei_out, qr!\A\Q$url\E\n\z!, 'ls-mail-sync output as-expected');
+
+       ok(!lei(qw(import), "$url/12-1"), 'backwards range rejected');
+
+       # new home
+       local $ENV{HOME} = "$tmpdir/h2";
+       lei_ok(qw(ls-mail-source -l), $url);
+       my $ls = json_utf8->decode($lei_out);
+       my ($high, $low) = @{$ls->[0]}{qw(high low)};
+       ok($high > $low, 'high > low');
+
+       my $end = $high - 1;
+       lei_ok qw(import), "$url/$high";
+       lei_ok qw(q z:0..); my $one = json_utf8->decode($lei_out);
+       pop @$one; # trailing null
+       is(scalar(@$one), 1, 'only 1 result');
+
+       local $ENV{HOME} = "$tmpdir/h3";
+       lei_ok qw(import), "$url/$low-$end";
+       lei_ok qw(q z:0..); my $start = json_utf8->decode($lei_out);
+       pop @$start; # trailing null
+       is(scalar(@$start), scalar(map { $_ } ($low..$end)),
+               'range worked as expected');
+       my %seen;
+       for (@$start, @$one) {
+               is($seen{$_->{blob}}++, 0, "blob $_->{blob} seen once");
+       }
 });
 done_testing;