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