From: Eric Wong <e@80x24.org> To: meta@public-inbox.org Subject: [PATCH 23/35] t/cgi: create_inbox Date: Mon, 15 Mar 2021 12:58:14 +0100 [thread overview] Message-ID: <20210315115826.17591-24-e@80x24.org> (raw) In-Reply-To: <20210315115826.17591-1-e@80x24.org> 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 <<EOF or BAIL_OUT $!; -[publicinbox "test"] - address = $addr - inboxdir = $maindir - indexlevel = basic -EOF - close $fh or BAIL_OUT $!; -} - -my $cfg = PublicInbox::Config->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(<<EOF); +require_mods(qw(Plack::Handler::CGI Plack::Util)); +my $slashy_mid = 'slashy/asdf@example.com'; +my $ibx = create_inbox 'test', tmpdir => "$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(<<EOF); From: Me <me\@example.com> To: You <you\@example.com> -Cc: $addr +Cc: $ibx->{-primary_address} Message-Id: <blah\@example.com> 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', '<toobig@example.com>'); - $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', '<toobig@example.com>'); + $eml->body_set("z\n" x 1024); + $im->add($eml) or BAIL_OUT; - # deliver a reply, too - $mime = PublicInbox::Eml->new(<<EOF); + $eml = PublicInbox::Eml->new(<<EOF); From: You <you\@example.com> To: Me <me\@example.com> -Cc: $addr +Cc: $ibx->{-primary_address} In-Reply-To: <blah\@example.com> Message-Id: <blahblah\@example.com> 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(<<EOF); + $im->add($eml) or BAIL_OUT; + $eml = PublicInbox::Eml->new(<<EOF); From: You <you\@example.com> To: Me <me\@example.com> -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 <<EOF or BAIL_OUT $!; +[publicinbox "test"] + address = $ibx->{-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) {
next prev parent reply other threads:[~2021-03-15 11:58 UTC|newest] Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-03-15 11:57 [PATCH 00/35] memoize inbox creations Eric Wong 2021-03-15 11:57 ` [PATCH 01/35] test_common: add create_inbox helper sub Eric Wong 2021-03-15 11:57 ` [PATCH 02/35] t/lei_xsearch: use create_inbox Eric Wong 2021-03-15 11:57 ` [PATCH 03/35] test_common: minor simplifications to setup_public_inboxes Eric Wong 2021-03-15 11:57 ` [PATCH 04/35] t/imapd-tls: switch to create_inbox Eric Wong 2021-03-15 11:57 ` [PATCH 05/35] t/www_altid: use create_inbox Eric Wong 2021-03-15 11:57 ` [PATCH 06/35] t/xcpdb-reshard: " Eric Wong 2021-03-15 11:57 ` [PATCH 07/35] t/v2dupindex: create_inbox Eric Wong 2021-03-15 11:57 ` [PATCH 08/35] t/admin: switch to create_inbox Eric Wong 2021-03-15 19:51 ` [SQUASH] " Eric Wong 2021-03-15 11:58 ` [PATCH 09/35] t/html_index: remove now-worthless test Eric Wong 2021-03-15 11:58 ` [PATCH 10/35] t/plack: use create_inbox Eric Wong 2021-03-15 11:58 ` [PATCH 11/35] t/psgi_attach: convert to create_inbox Eric Wong 2021-03-15 11:58 ` [PATCH 12/35] t/httpd: " Eric Wong 2021-03-15 11:58 ` [PATCH 13/35] t/convert-compact: create_inbox Eric Wong 2021-03-15 11:58 ` [PATCH 14/35] t/altid: use create_inbox Eric Wong 2021-03-15 11:58 ` [PATCH 15/35] t/psgi_mount: switch to create_inbox Eric Wong 2021-03-15 11:58 ` [PATCH 16/35] t/feed: " Eric Wong 2021-03-15 11:58 ` [PATCH 17/35] t/psgi_bad_mids: use create_inbox Eric Wong 2021-03-15 11:58 ` [PATCH 18/35] t/psgi_multipart_not: " Eric Wong 2021-03-15 11:58 ` [PATCH 19/35] t/psgi_scan_all: create_inbox lots saved Eric Wong 2021-03-15 11:58 ` [PATCH 20/35] t/psgi_v2: create_inbox Eric Wong 2021-03-15 11:58 ` [PATCH 21/35] t/imapd: create_inbox (minor) Eric Wong 2021-03-15 11:58 ` [PATCH 22/35] t/solver_git: use create_inbox Eric Wong 2021-03-15 11:58 ` Eric Wong [this message] 2021-03-15 11:58 ` [PATCH 24/35] t/edit: switch to create_inbox Eric Wong 2021-03-15 11:58 ` [PATCH 25/35] t/inbox_idle: " Eric Wong 2021-03-15 11:58 ` [PATCH 26/35] t/lei_xsearch: use create_inbox Eric Wong 2021-03-15 11:58 ` [PATCH 27/35] t/indexlevels-mirror: " Eric Wong 2021-03-15 11:58 ` [PATCH 28/35] t/multi-mid: " Eric Wong 2021-03-15 11:58 ` [PATCH 29/35] t/psgi_search: " Eric Wong 2021-03-15 11:58 ` [PATCH 30/35] t/miscsearch: " Eric Wong 2021-03-15 11:58 ` [PATCH 31/35] t/nntpd-tls: " Eric Wong 2021-03-15 11:58 ` [PATCH 32/35] t/nntpd: " Eric Wong 2021-03-15 11:58 ` [PATCH 33/35] t/thread-index-gap: create_inbox Eric Wong 2021-03-15 11:58 ` [PATCH 34/35] t/altid_v2: create_inbox Eric Wong 2021-03-15 11:58 ` [PATCH 35/35] t/*: disable fsync on tests were create_inbox isn't worth it Eric Wong
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: https://public-inbox.org/README * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210315115826.17591-24-e@80x24.org \ --to=e@80x24.org \ --cc=meta@public-inbox.org \ --subject='Re: [PATCH 23/35] t/cgi: create_inbox' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Code repositories for project(s) associated with this inbox: https://80x24.org/public-inbox.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).