]> Sergey Matveev's repositories - public-inbox.git/blob - t/psgi_scan_all.t
config: we always have {-section_order}
[public-inbox.git] / t / psgi_scan_all.t
1 # Copyright (C) 2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 use strict;
4 use warnings;
5 use Test::More;
6 use Email::MIME;
7 use File::Temp qw/tempdir/;
8 use PublicInbox::Config;
9 my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape DBD::SQLite);
10 foreach my $mod (@mods) {
11         eval "require $mod";
12         plan skip_all => "$mod missing for psgi_scan_all.t" if $@;
13 }
14 use_ok 'PublicInbox::V2Writable';
15 foreach my $mod (@mods) { use_ok $mod; }
16 my $tmp = tempdir('pi-scan_all-XXXXXX', TMPDIR => 1, CLEANUP => 1);
17 my $cfg = '';
18
19 foreach my $i (1..2) {
20         my $cfgpfx = "publicinbox.test-$i";
21         my $addr = "test-$i\@example.com";
22         my $mainrepo = "$tmp/$i";
23         $cfg .= "$cfgpfx.address=$addr\n";
24         $cfg .= "$cfgpfx.mainrepo=$mainrepo\n";
25         $cfg .= "$cfgpfx.url=http://example.com/$i\n";
26         my $opt = {
27                 mainrepo => $mainrepo,
28                 name => "test-$i",
29                 version => 2,
30                 indexlevel => 'basic',
31                 -primary_address => $addr,
32         };
33         my $ibx = PublicInbox::Inbox->new($opt);
34         my $im = PublicInbox::V2Writable->new($ibx, 1);
35         $im->{parallel} = 0;
36         $im->init_inbox(0);
37         my $mime = PublicInbox::MIME->new(<<EOF);
38 From: a\@example.com
39 To: $addr
40 Subject: s$i
41 Message-ID: <a-mid-$i\@b>
42 Date: Fri, 02 Oct 1993 00:00:00 +0000
43
44 hello world
45 EOF
46
47         ok($im->add($mime), "added message to $i");
48         $im->done;
49 }
50 my $config = PublicInbox::Config->new(\$cfg);
51 use_ok 'PublicInbox::WWW';
52 my $www = PublicInbox::WWW->new($config);
53
54 test_psgi(sub { $www->call(@_) }, sub {
55         my ($cb) = @_;
56         foreach my $i (1..2) {
57                 foreach my $end ('', '/') {
58                         my $res = $cb->(GET("/a-mid-$i\@b$end"));
59                         is($res->code, 302, 'got 302');
60                         is($res->header('Location'),
61                                 "http://example.com/$i/a-mid-$i\@b/",
62                                 "redirected OK to $i");
63                 }
64         }
65         foreach my $x (qw(inv@lid inv@lid/ i/v/a l/i/d/)) {
66                 my $res = $cb->(GET("/$x"));
67                 is($res->code, 404, "404 on $x");
68         }
69 });
70
71 done_testing();