-# Copyright (C) 2017-2018 all contributors <meta@public-inbox.org>
+# Copyright (C) 2017-2019 all contributors <meta@public-inbox.org>
# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
use strict;
use warnings;
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(PublicInbox::SearchIdx HTTP::Request::Common Plack::Test
+my @mods = qw(DBD::SQLite Search::Xapian HTTP::Request::Common Plack::Test
URI::Escape Plack::Builder);
foreach my $mod (@mods) {
eval "require $mod";
plan skip_all => "$mod missing for psgi_search.t" if $@;
}
-use_ok $_ foreach @mods;
+
+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 $rw = PublicInbox::SearchIdx->new($git_dir, 1);
-ok($rw, "search indexer created");
+my $ibx = PublicInbox::Inbox->new({
+ inboxdir => $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";
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,
-});
+my $config = PublicInbox::Config->new(\<<EOF);
+$cfgpfx.address=git\@vger.kernel.org
+$cfgpfx.inboxdir=$tmpdir
+EOF
my $www = PublicInbox::WWW->new($config);
test_psgi(sub { $www->call(@_) }, sub {
my ($cb) = @_;