unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] t/psgi_search.t: use higher-level APIs
Date: Sun, 16 Jun 2019 00:57:36 +0000	[thread overview]
Message-ID: <20190616005736.26324-1-e@80x24.org> (raw)

No point in using lower-level APIs for a PSGI test.
---
 t/psgi_search.t | 34 +++++++++++++++-------------------
 1 file changed, 15 insertions(+), 19 deletions(-)

diff --git a/t/psgi_search.t b/t/psgi_search.t
index bbf5a96..0c40a7f 100644
--- a/t/psgi_search.t
+++ b/t/psgi_search.t
@@ -7,6 +7,7 @@ use File::Temp qw/tempdir/;
 use Email::MIME;
 use PublicInbox::Config;
 use PublicInbox::Inbox;
+use PublicInbox::InboxWritable;
 use PublicInbox::WWW;
 use bytes (); # only for bytes::length
 my @mods = qw(DBD::SQLite Search::Xapian HTTP::Request::Common Plack::Test
@@ -15,14 +16,18 @@ foreach my $mod (@mods) {
 	eval "require $mod";
 	plan skip_all => "$mod missing for psgi_search.t" if $@;
 }
+
 use_ok $_ foreach (@mods, qw(PublicInbox::SearchIdx));
 my $tmpdir = tempdir('pi-psgi-search.XXXXXX', TMPDIR => 1, CLEANUP => 1);
-my $git_dir = "$tmpdir/a.git";
 
-is(0, system(qw(git init -q --bare), $git_dir), "git init (main)");
-my $ibx = PublicInbox::Inbox->new({mainrepo => $git_dir});
-my $rw = PublicInbox::SearchIdx->new($ibx, 1);
-ok($rw, "search indexer created");
+my $ibx = PublicInbox::Inbox->new({
+	mainrepo => $tmpdir,
+	address => 'git@vger.kernel.org',
+	name => 'test',
+});
+$ibx = PublicInbox::InboxWritable->new($ibx);
+$ibx->init_inbox(1);
+my $im = $ibx->importer(0);
 my $digits = '10010260936330';
 my $ua = 'Pine.LNX.4.10';
 my $mid = "$ua.$digits.2460-100000\@penguin.transmeta.com";
@@ -34,24 +39,15 @@ To: git\@vger.kernel.org
 
 EOF
 
-my $num = 0;
-# nb. using internal API, fragile!
-$rw->begin_txn_lazy;
-
-foreach (reverse split(/\n\n/, $data)) {
-	$_ .= "\n";
-	my $mime = Email::MIME->new(\$_);
-	my $bytes = bytes::length($mime->as_string);
-	my $doc_id = $rw->add_message($mime, $bytes, ++$num, 'ignored');
-	ok($doc_id, 'message added');
-}
-
-$rw->commit_txn_lazy;
+my $mime = Email::MIME->new(\$data);
+$im->add($mime);
+$im->done;
+PublicInbox::SearchIdx->new($ibx, 1)->index_sync;
 
 my $cfgpfx = "publicinbox.test";
 my $config = PublicInbox::Config->new({
 	"$cfgpfx.address" => 'git@vger.kernel.org',
-	"$cfgpfx.mainrepo" => $git_dir,
+	"$cfgpfx.mainrepo" => $tmpdir,
 });
 my $www = PublicInbox::WWW->new($config);
 test_psgi(sub { $www->call(@_) }, sub {
-- 
EW


                 reply	other threads:[~2019-06-16  0:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20190616005736.26324-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).