]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/lei-import-imap.t
No ext_urls
[public-inbox.git] / t / lei-import-imap.t
index 59d481d58216499fbb8bd73f24ecc58ef9074ec9..3b6cb29926eee322355365631ff636c3d261eb3b 100644 (file)
@@ -13,6 +13,13 @@ my $host_port = tcp_host_port($sock);
 undef $sock;
 test_lei({ tmpdir => $tmpdir }, sub {
        my $url = "imap://$host_port/t.v2.0";
+       my $url_orig = $url;
+       lei_ok(qw(ls-mail-source), "imap://$host_port/");
+       like($lei_out, qr/^t\.v2\.0$/ms, 'shows mailbox');
+       lei_ok(qw(ls-mail-source), $url);
+       is($lei_out, "t.v2.0\n", 'shows only mailbox with filter');
+       lei_ok(qw(ls-mail-source -l), "imap://$host_port/");
+       is(ref(json_utf8->decode($lei_out)), 'ARRAY', 'ls-mail-source JSON');
 
        lei_ok(qw(q z:1..));
        my $out = json_utf8->decode($lei_out);
@@ -36,6 +43,7 @@ test_lei({ tmpdir => $tmpdir }, sub {
        $url = $u;
        $u =~ s/;UIDVALIDITY=(\d+)\s*/;UIDVALIDITY=9$1/s;
        ok(!lei('import', $u), 'UIDVALIDITY mismatch in URL rejected');
+       like($lei_err, qr/UIDVALIDITY mismatch/, 'mismatch noted');
 
        lei_ok('inspect', $url);
        my $inspect = json_utf8->decode($lei_out);
@@ -48,6 +56,13 @@ test_lei({ tmpdir => $tmpdir }, sub {
        ok($stats->{'uid.min'} < $stats->{'uid.max'}, 'min < max');
        ok($stats->{'uid.count'} > 0, 'count > 0');
 
+       lei_ok('lcat', $url);
+       is(scalar(grep(/^# blob:/, split(/\n/ms, $lei_out))),
+               $stats->{'uid.count'}, 'lcat on URL dumps folder');
+       lei_ok qw(lcat -f json), $url;
+       $out = json_utf8->decode($lei_out);
+       is(scalar(@$out) - 1, $stats->{'uid.count'}, 'lcat JSON dumps folder');
+
        lei_ok(qw(q z:1..));
        $out = json_utf8->decode($lei_out);
        ok(scalar(@$out) > 1, 'got imported messages');
@@ -77,6 +92,8 @@ test_lei({ tmpdir => $tmpdir }, sub {
        unlike($lei_out, qr!\Q$host_port\E!, 'sync info gone after forget');
        my $uid_url = "$url/;UID=".$stats->{'uid.max'};
        lei_ok 'import', $uid_url;
+       lei_ok 'ls-mail-sync';
+       is($lei_out, "$url\n", 'ls-mail-sync added URL w/o UID');
        lei_ok 'inspect', $uid_url;
        $lei_out =~ /([a-f0-9]{40,})/ or
                xbail 'inspect missed blob with UID URL';
@@ -88,7 +105,14 @@ test_lei({ tmpdir => $tmpdir }, sub {
        my $orig = $lei_out;
        lei_ok 'lcat', "blob:$blob";
        is($lei_out, $orig, 'lcat understands blob:...');
-       ok(!lei('lcat', $url), "lcat doesn't work on IMAP URL w/o UID");
+       lei_ok qw(lcat -f json), $uid_url;
+       $out = json_utf8->decode($lei_out);
+       is(scalar(@$out), 2, 'got JSON') or diag explain($out);
+       lei_ok qw(lcat), $url_orig;
+       is($lei_out, $orig, 'lcat w/o UID works');
+
+       ok(!lei(qw(export-kw), $url_orig), 'export-kw fails on read-only IMAP');
+       like($lei_err, qr/does not support/, 'error noted in failure');
 });
 
 done_testing;