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