]> Sergey Matveev's repositories - public-inbox.git/blob - t/psgi_text.t
No ext_urls
[public-inbox.git] / t / psgi_text.t
1 # Copyright (C) 2016-2021 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 PublicInbox::Eml;
7 use PublicInbox::TestCommon;
8 my ($tmpdir, $for_destroy) = tmpdir();
9 my $maindir = "$tmpdir/main.git";
10 my $addr = 'test-public@example.com';
11 my $cfgpfx = "publicinbox.test";
12 my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape Plack::Builder);
13 require_mods(@mods, 'IO::Uncompress::Gunzip');
14 use_ok $_ foreach @mods;
15 use PublicInbox::Import;
16 use PublicInbox::Git;
17 use PublicInbox::Config;
18 use_ok 'PublicInbox::WWW';
19 use_ok 'PublicInbox::WwwText';
20 my $config = PublicInbox::Config->new(\<<EOF);
21 $cfgpfx.address=$addr
22 $cfgpfx.inboxdir=$maindir
23 EOF
24 PublicInbox::Import::init_bare($maindir);
25 my $www = PublicInbox::WWW->new($config);
26
27 test_psgi(sub { $www->call(@_) }, sub {
28         my ($cb) = @_;
29         my $gunzipped;
30         my $req = GET('/test/_/text/help/');
31         my $res = $cb->($req);
32         my $content = $res->content;
33         like($content, qr!<title>public-inbox help.*</title>!, 'default help');
34         $req->header('Accept-Encoding' => 'gzip');
35         $res = $cb->($req);
36         is($res->header('Content-Encoding'), 'gzip', 'got gzip encoding');
37         is($res->header('Content-Type'), 'text/html; charset=UTF-8',
38                 'got gzipped HTML');
39         IO::Uncompress::Gunzip::gunzip(\($res->content) => \$gunzipped);
40         is($gunzipped, $content, 'gzipped content is correct');
41
42         $req = GET('/test/_/text/config/raw');
43         $res = $cb->($req);
44         $content = $res->content;
45         my $olen = $res->header('Content-Length');
46         my $f = "$tmpdir/cfg";
47         open my $fh, '>', $f or die;
48         print $fh $content or die;
49         close $fh or die;
50         my $cfg = PublicInbox::Config->new($f);
51         is($cfg->{"$cfgpfx.address"}, $addr, 'got expected address in config');
52
53         $req->header('Accept-Encoding' => 'gzip');
54         $res = $cb->($req);
55         is($res->header('Content-Encoding'), 'gzip', 'got gzip encoding');
56         ok($res->header('Content-Length') < $olen, 'gzipped help is smaller');
57         IO::Uncompress::Gunzip::gunzip(\($res->content) => \$gunzipped);
58         is($gunzipped, $content);
59 });
60
61 done_testing();