From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 97FA21FD75 for ; Mon, 15 Mar 2021 11:58:31 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 23/35] t/cgi: create_inbox Date: Mon, 15 Mar 2021 12:58:14 +0100 Message-Id: <20210315115826.17591-24-e@80x24.org> In-Reply-To: <20210315115826.17591-1-e@80x24.org> References: <20210315115826.17591-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: This only saves a few ms but is nicer to look at. --- t/cgi.t | 84 +++++++++++++++++++++++---------------------------------- 1 file changed, 34 insertions(+), 50 deletions(-) diff --git a/t/cgi.t b/t/cgi.t index 567c2ee0..95e6e735 100644 --- a/t/cgi.t +++ b/t/cgi.t @@ -5,61 +5,34 @@ use strict; use v5.10.1; use PublicInbox::TestCommon; use IO::Uncompress::Gunzip qw(gunzip); -require_mods(qw(Plack::Handler::CGI Plack::Util)); -require PublicInbox::Eml; -require PublicInbox::Import; -require PublicInbox::Inbox; -require PublicInbox::InboxWritable; -require PublicInbox::Config; +use PublicInbox::Eml; +use IO::Handle; my ($tmpdir, $for_destroy) = tmpdir(); -my $home = "$tmpdir/pi-home"; -my $pi_home = "$home/.public-inbox"; -my $pi_config = "$pi_home/config"; -my $maindir = "$tmpdir/main.git"; -my $addr = 'test-public@example.com'; -PublicInbox::Import::init_bare($maindir); -{ - mkdir($home, 0755) or BAIL_OUT $!; - mkdir($pi_home, 0755) or BAIL_OUT $!; - open my $fh, '>>', $pi_config or BAIL_OUT $!; - print $fh <new($pi_config); -my $ibx = $cfg->lookup_name('test'); -my $im = PublicInbox::InboxWritable->new($ibx)->importer(0); - -{ - local $ENV{HOME} = $home; - - # inject some messages: - my $mime = PublicInbox::Eml->new(< "$tmpdir/test", sub { + my ($im, $ibx) = @_; + mkdir "$ibx->{inboxdir}/home", 0755 or BAIL_OUT; + mkdir "$ibx->{inboxdir}/home/.public-inbox", 0755 or BAIL_OUT; + my $eml = PublicInbox::Eml->new(< To: You -Cc: $addr +Cc: $ibx->{-primary_address} Message-Id: Subject: hihi Date: Thu, 01 Jan 1970 00:00:00 +0000 zzzzzz EOF - ok($im->add($mime), 'added initial message'); - - $mime->header_set('Message-ID', ''); - $mime->body_set("z\n" x 1024); - ok($im->add($mime), 'added big message'); + $im->add($eml) or BAIL_OUT; + $eml->header_set('Message-ID', ''); + $eml->body_set("z\n" x 1024); + $im->add($eml) or BAIL_OUT; - # deliver a reply, too - $mime = PublicInbox::Eml->new(<new(< To: Me -Cc: $addr +Cc: $ibx->{-primary_address} In-Reply-To: Message-Id: Subject: Re: hihi @@ -70,22 +43,31 @@ Me wrote: what? EOF - ok($im->add($mime), 'added reply'); - - my $slashy_mid = 'slashy/asdf@example.com'; - my $slashy = PublicInbox::Eml->new(<add($eml) or BAIL_OUT; + $eml = PublicInbox::Eml->new(< To: Me -Cc: $addr +Cc: $ibx->{-primary_address} Message-Id: <$slashy_mid> Subject: Re: hihi Date: Thu, 01 Jan 1970 00:00:01 +0000 slashy EOF - ok($im->add($slashy), 'added slash'); - $im->done; + $im->add($eml) or BAIL_OUT; +}; # create_inbox +my $home = "$ibx->{inboxdir}/home"; +open my $cfgfh, '>>', "$home/.public-inbox/config" or BAIL_OUT $!; +print $cfgfh <{-primary_address} + inboxdir = $ibx->{inboxdir} +EOF +$cfgfh->flush or BAIL_OUT $!; + +{ + local $ENV{HOME} = $home; my $res = cgi_run("/test/slashy/asdf\@example.com/raw"); like($res->{body}, qr/Message-Id: <\Q$slashy_mid\E>/, "slashy mid raw hit"); @@ -98,6 +80,8 @@ SKIP: { my $res = cgi_run($path); like($res->{head}, qr/^Status: 501 /, "search not-yet-enabled"); my $cmd = ['-index', $ibx->{inboxdir}, '--max-size=2k']; + print $cfgfh "\tindexlevel = basic\n" or BAIL_OUT $!; + $cfgfh->flush or BAIL_OUT $!; my $opt = { 2 => \(my $err) }; my $indexed = run_script($cmd, undef, $opt); if ($indexed) {