]> Sergey Matveev's repositories - public-inbox.git/blob - t/psgi_text.t
config: we always have {-section_order}
[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 File::Temp qw/tempdir/;
8 my $tmpdir = tempdir('psgi-text-XXXXXX', TMPDIR => 1, CLEANUP => 1);
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 foreach my $mod (@mods) {
14         eval "require $mod";
15         plan skip_all => "$mod missing for psgi_text.t" if $@;
16 }
17 use_ok $_ foreach @mods;
18 use PublicInbox::Import;
19 use PublicInbox::Git;
20 use PublicInbox::Config;
21 use PublicInbox::WWW;
22 use_ok 'PublicInbox::WwwText';
23 use Plack::Builder;
24 my $config = PublicInbox::Config->new(\<<EOF);
25 $cfgpfx.address=$addr
26 $cfgpfx.mainrepo=$maindir
27 EOF
28 is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
29 my $www = PublicInbox::WWW->new($config);
30
31 test_psgi(sub { $www->call(@_) }, sub {
32         my ($cb) = @_;
33         my $res;
34         $res = $cb->(GET('/test/_/text/help/'));
35         like($res->content, qr!<title>public-inbox help.*</title>!,
36                 'default help');
37         $res = $cb->(GET('/test/_/text/config/raw'));
38         my $f = "$tmpdir/cfg";
39         open my $fh, '>', $f or die;
40         print $fh $res->content or die;
41         close $fh or die;
42         my $cfg = PublicInbox::Config->new($f);
43         is($cfg->{"$cfgpfx.address"}, $addr, 'got expected address in config');
44 });
45
46 done_testing();