]> Sergey Matveev's repositories - public-inbox.git/blob - t/psgi_text.t
treewide: run update-copyrights from gnulib for 2019
[public-inbox.git] / t / psgi_text.t
1 # Copyright (C) 2016-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::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);
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 is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
25 my $www = PublicInbox::WWW->new($config);
26
27 test_psgi(sub { $www->call(@_) }, sub {
28         my ($cb) = @_;
29         my $res;
30         $res = $cb->(GET('/test/_/text/help/'));
31         like($res->content, qr!<title>public-inbox help.*</title>!,
32                 'default help');
33         $res = $cb->(GET('/test/_/text/config/raw'));
34         my $f = "$tmpdir/cfg";
35         open my $fh, '>', $f or die;
36         print $fh $res->content or die;
37         close $fh or die;
38         my $cfg = PublicInbox::Config->new($f);
39         is($cfg->{"$cfgpfx.address"}, $addr, 'got expected address in config');
40 });
41
42 done_testing();