]> Sergey Matveev's repositories - public-inbox.git/blob - t/psgi_text.t
testcommon: add require_mods method and use it
[public-inbox.git] / t / psgi_text.t
1 # Copyright (C) 2016-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 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);
13 require_mods(@mods);
14 use_ok $_ foreach @mods;
15 use PublicInbox::Import;
16 use PublicInbox::Git;
17 use PublicInbox::Config;
18 use PublicInbox::WWW;
19 use_ok 'PublicInbox::WwwText';
20 use Plack::Builder;
21 my $config = PublicInbox::Config->new(\<<EOF);
22 $cfgpfx.address=$addr
23 $cfgpfx.inboxdir=$maindir
24 EOF
25 is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
26 my $www = PublicInbox::WWW->new($config);
27
28 test_psgi(sub { $www->call(@_) }, sub {
29         my ($cb) = @_;
30         my $res;
31         $res = $cb->(GET('/test/_/text/help/'));
32         like($res->content, qr!<title>public-inbox help.*</title>!,
33                 'default help');
34         $res = $cb->(GET('/test/_/text/config/raw'));
35         my $f = "$tmpdir/cfg";
36         open my $fh, '>', $f or die;
37         print $fh $res->content or die;
38         close $fh or die;
39         my $cfg = PublicInbox::Config->new($f);
40         is($cfg->{"$cfgpfx.address"}, $addr, 'got expected address in config');
41 });
42
43 done_testing();