]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/solver_git.t
lei blob: add remote external support
[public-inbox.git] / t / solver_git.t
index 99ffb9e353cb691c125e5866ebfdfc8474e84f90..2d803d47a4944cb1a8c368f4a58c520e0ffbb93a 100644 (file)
@@ -6,7 +6,8 @@ use v5.10.1;
 use PublicInbox::TestCommon;
 use Cwd qw(abs_path);
 require_git(2.6);
-use PublicInbox::Spawn qw(popen_rd);
+use Digest::SHA qw(sha1_hex);
+use PublicInbox::Spawn qw(popen_rd which);
 require_mods(qw(DBD::SQLite Search::Xapian Plack::Util));
 my $git_dir = xqx([qw(git rev-parse --git-dir)], undef, {2 => \(my $null)});
 $? == 0 or plan skip_all => "$0 must be run from a git working tree";
@@ -27,6 +28,41 @@ my $ibx = create_inbox 'v2', version => 2,
 };
 my $v1_0_0_tag = 'cb7c42b1e15577ed2215356a2bf925aef59cdd8d';
 my $v1_0_0_tag_short = substr($v1_0_0_tag, 0, 16);
+my $expect = '69df7d565d49fbaaeb0a067910f03dc22cd52bd0';
+my $non_existent = 'ee5e32211bf62ab6531bdf39b84b6920d0b6775a';
+
+test_lei({tmpdir => $tmpdir}, sub {
+       lei_ok('blob', '69df7d5', '-I', $ibx->{inboxdir});
+       is(sha1_hex("blob ".length($lei_out)."\0".$lei_out),
+               $expect, 'blob contents output');
+       my $prev = $lei_out;
+       lei_ok(qw(blob --no-mail 69df7d5 -I), $ibx->{inboxdir});
+       is($lei_out, $prev, '--no-mail works');
+       ok(!lei(qw(blob -I), $ibx->{inboxdir}, $non_existent),
+                       'non-existent blob fails');
+       SKIP: {
+               skip '/.git exists', 1 if -e '/.git';
+               require PublicInbox::OnDestroy;
+               opendir my $dh, '.' or xbail "opendir: $!";
+               my $end = PublicInbox::OnDestroy->new($$, sub {
+                       chdir $dh or xbail "chdir: $!";
+               });
+               lei_ok(qw(-C / blob 69df7d5 -I), $ibx->{inboxdir},
+                       "--git-dir=$git_dir");
+               is($lei_out, $prev, '--git-dir works');
+
+               ok(!lei(qw(-C / blob --no-cwd 69df7d5 -I), $ibx->{inboxdir}),
+                       '--no-cwd works');
+
+               ok(!lei(qw(-C / blob -I), $ibx->{inboxdir}, $non_existent),
+                       'non-existent blob fails');
+       }
+
+       # fallbacks
+       lei_ok('blob', $v1_0_0_tag, '-I', $ibx->{inboxdir});
+       lei_ok('blob', $v1_0_0_tag_short, '-I', $ibx->{inboxdir});
+});
+
 my $git = PublicInbox::Git->new($git_dir);
 $ibx->{-repo_objs} = [ $git ];
 my $res;
@@ -38,7 +74,6 @@ $solver->solve($psgi_env, $log, '69df7d5', {});
 ok($res, 'solved a blob!');
 my $wt_git = $res->[0];
 is(ref($wt_git), 'PublicInbox::Git', 'got a git object for the blob');
-my $expect = '69df7d565d49fbaaeb0a067910f03dc22cd52bd0';
 is($res->[1], $expect, 'resolved blob to unabbreviated identifier');
 is($res->[2], 'blob', 'type specified');
 is($res->[3], 4405, 'size returned');
@@ -148,7 +183,6 @@ EOF
        close $cfgfh or die;
        my $cfg = PublicInbox::Config->new($cfgpath);
        my $www = PublicInbox::WWW->new($cfg);
-       my $non_existent = 'ee5e32211bf62ab6531bdf39b84b6920d0b6775a';
        my $client = sub {
                my ($cb) = @_;
                my $mid = '20190401081523.16213-1-BOFH@YHBT.net';
@@ -193,8 +227,20 @@ EOF
                my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ];
                my $td = start_script($cmd, $env, { 3 => $sock });
                my ($h, $p) = tcp_host_port($sock);
-               local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://$h:$p";
+               my $url = "http://$h:$p";
+               local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = $url;
                Plack::Test::ExternalServer::test_psgi(client => $client);
+               skip 'no curl', 1 unless which('curl');
+
+               mkdir "$tmpdir/ext" // xbail "mkdir $!";
+               test_lei({tmpdir => "$tmpdir/ext"}, sub {
+                       my $rurl = "$url/$name";
+                       lei_ok(qw(blob --no-mail 69df7d5 -I), $rurl);
+                       is(sha1_hex("blob ".length($lei_out)."\0".$lei_out),
+                               $expect, 'blob contents output');
+                       ok(!lei(qw(blob -I), $rurl, $non_existent),
+                                       'non-existent blob fails');
+               });
        }
 }