lei/store: stop shard workers + cat-file on idle
[public-inbox.git] / t / psgi_mount.t
blobe43b9f2d8f77886b975ed426f608ffb48e2b749b
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::Eml;
6 use PublicInbox::TestCommon;
7 my ($tmpdir, $for_destroy) = tmpdir();
8 my $v1dir = "$tmpdir/v1.git";
9 my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape
10         Plack::Builder Plack::App::URLMap);
11 require_mods(@mods);
12 use_ok $_ foreach @mods;
13 use_ok 'PublicInbox::WWW';
14 my $ibx = create_inbox 'test', tmpdir => $v1dir, sub {
15         my ($im, $ibx) = @_;
16         $im->add(PublicInbox::Eml->new(<<EOF)) or BAIL_OUT;
17 From: Me <me\@example.com>
18 To: You <you\@example.com>
19 Cc: $ibx->{-primary_address}
20 Message-Id: <blah\@example.com>
21 Subject: hihi
22 Date: Thu, 01 Jan 1970 00:00:00 +0000
24 zzzzzz
25 EOF
27 my $cfg = cfg_new $tmpdir, <<EOF;
28 [publicinbox "test"]
29         address = $ibx->{-primary_address}
30         inboxdir = $v1dir
31 EOF
32 my $www = PublicInbox::WWW->new($cfg);
33 my $app = builder(sub {
34         enable('Head');
35         mount('/a' => builder(sub { sub { $www->call(@_) } }));
36         mount('/b' => builder(sub { sub { $www->call(@_) } }));
37 });
39 test_psgi($app, sub {
40         my ($cb) = @_;
41         my $res;
42         # Atom feed:
43         $res = $cb->(GET('/a/test/new.atom'));
44         like($res->content, qr!\bhttp://[^/]+/a/test/!,
45                 'URLs which exist in Atom feed are mount-aware');
46         unlike($res->content, qr!\b\Qhttp://[^/]+/test/\E!,
47                 'No URLs which are not mount-aware');
49         $res = $cb->(GET('/a/test/_/text/mirror/'));
50         like($res->content, qr!git clone --mirror\s+.*?http://[^/]+/a/test\b!s,
51                 'clone URL in /text/mirror is mount-aware');
53         $res = $cb->(GET('/a/test/blah%40example.com/raw'));
54         is($res->code, 200, 'OK with URLMap mount');
55         like($res->content,
56                 qr/^Message-Id: <blah\@example\.com>\n/sm,
57                 'headers appear in /raw');
59         # redirects
60         $res = $cb->(GET('/a/test/m/blah%40example.com.html'));
61         is($res->header('Location'),
62                 'http://localhost/a/test/blah@example.com/',
63                 'redirect functions properly under mount');
65         $res = $cb->(GET('/test/blah%40example.com/'));
66         is($res->code, 404, 'intentional 404 with URLMap mount');
67 });
69 SKIP: {
70         require_mods(qw(DBD::SQLite Xapian IO::Uncompress::Gunzip), 3);
71         require_ok 'PublicInbox::SearchIdx';
72         PublicInbox::SearchIdx->new($ibx, 1)->index_sync;
73         test_psgi($app, sub {
74                 my ($cb) = @_;
75                 my $res = $cb->(GET('/a/test/blah@example.com/t.mbox.gz'));
76                 my $gz = $res->content;
77                 my $raw;
78                 IO::Uncompress::Gunzip::gunzip(\$gz => \$raw);
79                 like($raw, qr!^Message-Id:\x20<blah\@example\.com>\n!sm,
80                         'headers appear in /t.mbox.gz mboxrd');
81         });
84 done_testing();