]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/psgi_scan_all.t
www: drop --subject from "git send-email" instructions
[public-inbox.git] / t / psgi_scan_all.t
index 2e00b6d843160e43391f2d54b8dc5227f181b42f..09e8eaf921dce304eb21ab0550559ccb68bd210c 100644 (file)
@@ -1,55 +1,38 @@
-# Copyright (C) 2019 all contributors <meta@public-inbox.org>
+#!perl -w
+# Copyright (C) 2019-2021 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use warnings;
-use Test::More;
-use Email::MIME;
-use File::Temp qw/tempdir/;
+use v5.10.1;
+use PublicInbox::TestCommon;
+use PublicInbox::Eml;
 use PublicInbox::Config;
 my @mods = qw(HTTP::Request::Common Plack::Test URI::Escape DBD::SQLite);
-foreach my $mod (@mods) {
-       eval "require $mod";
-       plan skip_all => "$mod missing for psgi_scan_all.t" if $@;
-}
-use_ok 'PublicInbox::V2Writable';
+require_git 2.6;
+require_mods(@mods);
+use_ok 'PublicInbox::WWW';
 foreach my $mod (@mods) { use_ok $mod; }
-my $tmp = tempdir('pi-scan_all-XXXXXX', TMPDIR => 1, CLEANUP => 1);
 my $cfg = '';
-
 foreach my $i (1..2) {
-       my $cfgpfx = "publicinbox.test-$i";
-       my $addr = "test-$i\@example.com";
-       my $mainrepo = "$tmp/$i";
-       $cfg .= "$cfgpfx.address=$addr\n";
-       $cfg .= "$cfgpfx.mainrepo=$mainrepo\n";
-       $cfg .= "$cfgpfx.url=http://example.com/$i\n";
-       my $opt = {
-               mainrepo => $mainrepo,
-               name => "test-$i",
-               version => 2,
-               indexlevel => 'basic',
-               -primary_address => $addr,
-       };
-       my $ibx = PublicInbox::Inbox->new($opt);
-       my $im = PublicInbox::V2Writable->new($ibx, 1);
-       $im->{parallel} = 0;
-       $im->init_inbox(0);
-       my $mime = PublicInbox::MIME->new(<<EOF);
+       my $ibx = create_inbox "test-$i", version => 2, indexlevel => 'basic',
+       sub {
+               my ($im, $ibx) = @_;
+               $im->add(PublicInbox::Eml->new(<<EOF)) or BAIL_OUT;
 From: a\@example.com
-To: $addr
+To: $ibx->{-primary_address}
 Subject: s$i
 Message-ID: <a-mid-$i\@b>
 Date: Fri, 02 Oct 1993 00:00:00 +0000
 
 hello world
 EOF
+       };
+       my $cfgpfx = "publicinbox.test-$i";
+       $cfg .= "$cfgpfx.address=$ibx->{-primary_address}\n";
+       $cfg .= "$cfgpfx.inboxdir=$ibx->{inboxdir}\n";
+       $cfg .= "$cfgpfx.url=http://example.com/$i\n";
 
-       ok($im->add($mime), "added message to $i");
-       $im->done;
 }
-my $config = PublicInbox::Config->new(\$cfg);
-use_ok 'PublicInbox::WWW';
-my $www = PublicInbox::WWW->new($config);
+my $www = PublicInbox::WWW->new(PublicInbox::Config->new(\$cfg));
 
 test_psgi(sub { $www->call(@_) }, sub {
        my ($cb) = @_;
@@ -67,5 +50,4 @@ test_psgi(sub { $www->call(@_) }, sub {
                is($res->code, 404, "404 on $x");
        }
 });
-
-done_testing();
+done_testing;