]> Sergey Matveev's repositories - public-inbox.git/blob - xt/solver.t
40a5f81fb0eb21f090aed59a851e3a1e503b7290
[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                 'c2f3bf071ee90b01f2d629921bb04c4f798f02fa/s/', # tag
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 "$url failed";
45                 diag $res->content;
46         }
47 };
48
49 my $nr = 0;
50 while (($ibx_name, $urls) = each %$todo) {
51         SKIP: {
52                 my $ibx = $cfg->lookup_name($ibx_name);
53                 if (!$ibx) {
54                         push @gone, $ibx_name;
55                         skip(qq{[publicinbox "$ibx_name"] not configured},
56                                 scalar(@$urls));
57                 }
58                 if (!defined($ibx->{coderepo})) {
59                         push @gone, $ibx_name;
60                         skip(qq{publicinbox.$ibx_name.coderepo not configured},
61                                 scalar(@$urls));
62                 }
63                 test_psgi($app, $client);
64                 $nr++;
65         }
66 }
67
68 delete @$todo{@gone};
69 my $env = { PI_CONFIG => PublicInbox::Config->default_file };
70 while (($ibx_name, $urls) = each %$todo) {
71         test_httpd($env, $client, $nr);
72 }
73
74 done_testing();