]> Sergey Matveev's repositories - public-inbox.git/blob - t/psgi_scan_all.t
treewide: run update-copyrights from gnulib for 2019
[public-inbox.git] / t / psgi_scan_all.t
1 # Copyright (C) 2019-2020 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 PublicInbox::Config;
8 use PublicInbox::TestCommon;
9 my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape DBD::SQLite);
10 require_mods(@mods);
11 use_ok 'PublicInbox::V2Writable';
12 foreach my $mod (@mods) { use_ok $mod; }
13 my ($tmp, $for_destroy) = tmpdir();
14 my $cfg = '';
15
16 foreach my $i (1..2) {
17         my $cfgpfx = "publicinbox.test-$i";
18         my $addr = "test-$i\@example.com";
19         my $inboxdir = "$tmp/$i";
20         $cfg .= "$cfgpfx.address=$addr\n";
21         $cfg .= "$cfgpfx.inboxdir=$inboxdir\n";
22         $cfg .= "$cfgpfx.url=http://example.com/$i\n";
23         my $opt = {
24                 inboxdir => $inboxdir,
25                 name => "test-$i",
26                 version => 2,
27                 indexlevel => 'basic',
28                 -primary_address => $addr,
29         };
30         my $ibx = PublicInbox::Inbox->new($opt);
31         my $im = PublicInbox::V2Writable->new($ibx, 1);
32         $im->{parallel} = 0;
33         $im->init_inbox(0);
34         my $mime = PublicInbox::MIME->new(<<EOF);
35 From: a\@example.com
36 To: $addr
37 Subject: s$i
38 Message-ID: <a-mid-$i\@b>
39 Date: Fri, 02 Oct 1993 00:00:00 +0000
40
41 hello world
42 EOF
43
44         ok($im->add($mime), "added message to $i");
45         $im->done;
46 }
47 my $config = PublicInbox::Config->new(\$cfg);
48 use_ok 'PublicInbox::WWW';
49 my $www = PublicInbox::WWW->new($config);
50
51 test_psgi(sub { $www->call(@_) }, sub {
52         my ($cb) = @_;
53         foreach my $i (1..2) {
54                 foreach my $end ('', '/') {
55                         my $res = $cb->(GET("/a-mid-$i\@b$end"));
56                         is($res->code, 302, 'got 302');
57                         is($res->header('Location'),
58                                 "http://example.com/$i/a-mid-$i\@b/",
59                                 "redirected OK to $i");
60                 }
61         }
62         foreach my $x (qw(inv@lid inv@lid/ i/v/a l/i/d/)) {
63                 my $res = $cb->(GET("/$x"));
64                 is($res->code, 404, "404 on $x");
65         }
66 });
67
68 done_testing();