]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/lei-externals.t
search: use git approxidate in WWW and "lei q --stdin"
[public-inbox.git] / t / lei-externals.t
index 739f779da41de2402e2c59e1ce72df21d1d78109..f61b7e52c95e4c1378b9d49c9ccbfed156cd0f37 100644 (file)
@@ -4,42 +4,13 @@
 use strict; use v5.10.1; use PublicInbox::TestCommon;
 use Fcntl qw(SEEK_SET);
 use PublicInbox::Spawn qw(which);
+require_git 2.6;
+require_mods(qw(DBD::SQLite Search::Xapian));
 
 my @onions = qw(http://hjrcffqmbrq6wope.onion/meta/
        http://czquwvybam4bgbro.onion/meta/
        http://ou63pmih66umazou.onion/meta/);
 
-# TODO share this across tests, it takes ~300ms
-my $setup_publicinboxes = sub {
-       my ($home) = @_;
-       use PublicInbox::InboxWritable;
-       for my $V (1, 2) {
-               run_script([qw(-init), "-V$V", "t$V",
-                               '--newsgroup', "t.$V",
-                               "$home/t$V", "http://example.com/t$V",
-                               "t$V\@example.com" ]) or BAIL_OUT "init v$V";
-       }
-       my $cfg = PublicInbox::Config->new;
-       my $seen = 0;
-       $cfg->each_inbox(sub {
-               my ($ibx) = @_;
-               my $im = PublicInbox::InboxWritable->new($ibx)->importer(0);
-               my $V = $ibx->version;
-               my @eml = (glob('t/*.eml'), 't/data/0001.patch');
-               for (@eml) {
-                       next if $_ eq 't/psgi_v2-old.eml'; # dup mid
-                       $im->add(eml_load($_)) or BAIL_OUT "v$V add $_";
-                       $seen++;
-               }
-               $im->done;
-               if ($V == 1) {
-                       run_script(['-index', $ibx->{inboxdir}]) or
-                               BAIL_OUT 'index v1';
-               }
-       });
-       $seen || BAIL_OUT 'no imports';
-};
-
 my $test_external_remote = sub {
        my ($url, $k) = @_;
 SKIP: {
@@ -59,25 +30,25 @@ SKIP: {
 } # /SKIP
 }; # /sub
 
+my ($ro_home, $cfg_path) = setup_public_inboxes;
 test_lei(sub {
        my $home = $ENV{HOME};
-       $setup_publicinboxes->($home);
        my $config_file = "$home/.config/lei/config";
        my $store_dir = "$home/.local/share/lei";
-       ok($lei->('ls-external'), 'ls-external works');
+       lei_ok 'ls-external', \'ls-external on fresh install';
        is($lei_out.$lei_err, '', 'ls-external no output, yet');
        ok(!-e $config_file && !-e $store_dir,
                'nothing created by ls-external');
 
-       ok(!$lei->('add-external', "$home/nonexistent"),
-               "fails on non-existent dir");
-       ok($lei->('ls-external'), 'ls-external works after add failure');
+       ok(!lei('add-external', "$home/nonexistent",
+               "fails on non-existent dir"));
+       lei_ok('ls-external', \'ls-external works after add failure');
        is($lei_out.$lei_err, '', 'ls-external still has no output');
-       my $cfg = PublicInbox::Config->new;
+       my $cfg = PublicInbox::Config->new($cfg_path);
        $cfg->each_inbox(sub {
                my ($ibx) = @_;
-               ok($lei->(qw(add-external -q), $ibx->{inboxdir}),
-                       'added external');
+               lei_ok(qw(add-external -q), $ibx->{inboxdir},
+                               \'added external');
                is($lei_out.$lei_err, '', 'no output');
        });
        ok(-s $config_file && -e $store_dir,
@@ -88,12 +59,30 @@ test_lei(sub {
                is($lcfg->{"external.$ibx->{inboxdir}.boost"}, 0,
                        "configured boost on $ibx->{name}");
        });
-       $lei->('ls-external');
+       lei_ok 'ls-external';
        like($lei_out, qr/boost=0\n/s, 'ls-external has output');
-       ok($lei->(qw(add-external -q https://EXAMPLE.com/ibx)), 'add remote');
+       lei_ok qw(add-external -q https://EXAMPLE.com/ibx), \'add remote';
        is($lei_err, '', 'no warnings after add-external');
 
-       ok($lei->(qw(_complete lei forget-external)), 'complete for externals');
+       {
+               lei_ok qw(ls-external --remote);
+               my $r_only = +{ map { $_ => 1 } split(/^/m, $lei_out) };
+               lei_ok qw(ls-external --local);
+               my $l_only = +{ map { $_ => 1 } split(/^/m, $lei_out) };
+               lei_ok 'ls-external';
+               is_deeply([grep { $l_only->{$_} } keys %$r_only], [],
+                       'no locals in --remote');
+               is_deeply([grep { $r_only->{$_} } keys %$l_only], [],
+                       'no remotes in --local');
+               my $all = +{ map { $_ => 1 } split(/^/m, $lei_out) };
+               is_deeply($all, { %$r_only, %$l_only },
+                               'default output combines remote + local');
+               lei_ok qw(ls-external --remote --local);
+               my $both = +{ map { $_ => 1 } split(/^/m, $lei_out) };
+               is_deeply($all, $both, '--remote --local == no args');
+       }
+
+       lei_ok qw(_complete lei forget-external), \'complete for externals';
        my %comp = map { $_ => 1 } split(/\s+/, $lei_out);
        ok($comp{'https://example.com/ibx/'}, 'forget external completion');
        $cfg->each_inbox(sub {
@@ -162,7 +151,7 @@ SKIP: {
        {
                open my $fh, '+>', undef or BAIL_OUT $!;
                $fh->autoflush(1);
-               print $fh 's:use' or BAIL_OUT $!;
+               print $fh 's:use d:..5.days.from.now' or BAIL_OUT $!;
                seek($fh, 0, SEEK_SET) or BAIL_OUT $!;
                ok($lei->([qw(q -q --stdin)], undef, { %$lei_opt, 0 => $fh }),
                                '--stdin on regular file works');