]> Sergey Matveev's repositories - public-inbox.git/blob - xt/solver.t
32cd43cf2fec47bbc50b3ee1d33e92abc73f3c65
[public-inbox.git] / xt / solver.t
1 #!perl -w
2 # Copyright (C) all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use v5.12;
5 use PublicInbox::TestCommon;
6 use PublicInbox::Config; # this relies on PI_CONFIG // ~/.public-inbox/config
7 my @psgi = qw(HTTP::Request::Common Plack::Test URI::Escape Plack::Builder);
8 require_mods(qw(DBD::SQLite Search::Xapian), @psgi);
9 use_ok($_) for @psgi;
10 use_ok 'PublicInbox::WWW';
11 my $cfg = PublicInbox::Config->new;
12 my $www = PublicInbox::WWW->new($cfg);
13 my $app = sub {
14         my $env = shift;
15         $env->{'psgi.errors'} = \*STDERR;
16         $www->call($env);
17 };
18
19 # TODO: convert these to self-contained test cases
20 my $todo = {
21         'git' => [
22                 '9e9048b02bd04d287461543d85db0bb715b89f8c'
23                         .'/s/?b=t%2Ft3420%2Fremove-ids.sed',
24                 'eebf7a8/s/?b=t%2Ftest-lib.sh',
25                 'eb580ca513/s/?b=remote-odb.c',
26                 '776fa90f7f/s/?b=contrib/git-jump/git-jump',
27                 '5cd8845/s/?b=submodule.c',
28                 '81c1164ae5/s/?b=builtin/log.c',
29                 '6aa8857a11/s/?b=protocol.c',
30                 '96f1c7f/s/', # TODO: b=contrib/completion/git-completion.bash
31                 'b76f2c0/s/?b=po/zh_CN.po',
32         ],
33 };
34
35 my ($ibx_name, $urls, @gone);
36 my $client = sub {
37         my ($cb) = @_;
38         for (@$urls) {
39                 my $url = "/$ibx_name/$_";
40                 my $res = $cb->(GET($url));
41                 is($res->code, 200, $url);
42                 next if $res->code == 200;
43                 diag "$url failed";
44                 diag $res->content;
45         }
46 };
47
48 my $nr = 0;
49 while (($ibx_name, $urls) = each %$todo) {
50         SKIP: {
51                 if (!$cfg->lookup_name($ibx_name)) {
52                         push @gone, $ibx_name;
53                         skip("$ibx_name not configured", scalar(@$urls));
54                 }
55                 test_psgi($app, $client);
56                 $nr++;
57         }
58 }
59
60 SKIP: {
61         require_mods(qw(Plack::Test::ExternalServer), $nr);
62         delete @$todo{@gone};
63
64         my $sock = tcp_server() or BAIL_OUT $!;
65         my ($tmpdir, $for_destroy) = tmpdir();
66         my ($out, $err) = map { "$tmpdir/std$_.log" } qw(out err);
67         my $cmd = [ qw(-httpd -W0), "--stdout=$out", "--stderr=$err" ];
68         my $td = start_script($cmd, undef, { 3 => $sock });
69         my ($h, $p) = tcp_host_port($sock);
70         local $ENV{PLACK_TEST_EXTERNALSERVER_URI} = "http://$h:$p";
71         while (($ibx_name, $urls) = each %$todo) {
72                 Plack::Test::ExternalServer::test_psgi(client => $client);
73         }
74 }
75
76 done_testing();