X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Fwatch_filter_rubylang.t;h=004e794ec8c224cedc7ac4e5bd63cdcb23553a95;hb=refs%2Fheads%2Fmaster;hp=da383c15ef4b294cbf5c047395474a8f88e66354;hpb=99566f264b4a13f5e9096411f1c87c4def153ab1;p=public-inbox.git diff --git a/t/watch_filter_rubylang.t b/t/watch_filter_rubylang.t index da383c15..004e794e 100644 --- a/t/watch_filter_rubylang.t +++ b/t/watch_filter_rubylang.t @@ -1,21 +1,15 @@ -# Copyright (C) 2019 all contributors +# Copyright (C) 2019-2021 all contributors # License: AGPL-3.0+ use strict; use warnings; -require './t/common.perl'; +use PublicInbox::TestCommon; use Test::More; -use File::Temp qw/tempdir/; -use PublicInbox::MIME; +use PublicInbox::Eml; use PublicInbox::Config; -my @mods = qw(Filesys::Notify::Simple DBD::SQLite Search::Xapian); -foreach my $mod (@mods) { - eval "require $mod"; - plan skip_all => "$mod missing for watch_filter_rubylang_v2.t" if $@; -} - -use_ok 'PublicInbox::WatchMaildir'; +require_mods(qw(DBD::SQLite Search::Xapian)); +use_ok 'PublicInbox::Watch'; use_ok 'PublicInbox::Emergency'; -my $tmpdir = tempdir('watch-XXXXXX', TMPDIR => 1, CLEANUP => 1); +my ($tmpdir, $for_destroy) = tmpdir(); local $ENV{PI_CONFIG} = "$tmpdir/pi_config"; my @v = qw(V1); @@ -30,18 +24,15 @@ SKIP: { for my $v (@v) { my @warn; - $SIG{__WARN__} = sub { push @warn, @_ }; + local $SIG{__WARN__} = sub { push @warn, @_ }; my $cfgpfx = "publicinbox.$v"; - my $mainrepo = "$tmpdir/$v"; + my $inboxdir = "$tmpdir/$v"; my $maildir = "$tmpdir/md-$v"; my $spamdir = "$tmpdir/spam-$v"; my $addr = "test-$v\@example.com"; - my @cmd = ('blib/script/public-inbox-init', "-$v", $v, $mainrepo, + my @cmd = ('-init', '-Lfull', "-$v", $v, $inboxdir, "http://example.com/$v", $addr); - is(system(@cmd), 0, 'public-inbox init OK'); - if ($v eq 'V1') { - is(system('blib/script/public-inbox-index', $mainrepo), 0); - } + ok(run_script(\@cmd), 'public-inbox init'); PublicInbox::Emergency->new($spamdir); for my $i (1..15) { @@ -70,32 +61,32 @@ spam EOF PublicInbox::Emergency->new($maildir)->prepare(\"$spam"); - my %orig = ( - "$cfgpfx.address" => $addr, - "$cfgpfx.mainrepo" => $mainrepo, - "$cfgpfx.watch" => "maildir:$maildir", - "$cfgpfx.filter" => 'PublicInbox::Filter::RubyLang', - "$cfgpfx.altid" => 'serial:alerts:file=msgmap.sqlite3', - "publicinboxwatch.watchspam" => "maildir:$spamdir", - ); - my $config = PublicInbox::Config->new({%orig}); - my $ibx = $config->lookup_name($v); + my $orig = <new(\$orig); + my $ibx = $cfg->lookup_name($v); + $ibx->{-no_fsync} = 1; ok($ibx, 'found inbox by name'); - my $w = PublicInbox::WatchMaildir->new($config); + my $w = PublicInbox::Watch->new($cfg); for my $i (1..2) { $w->scan('full'); } # make sure all serials are searchable: - my ($tot, $msgs); for my $i (1..15) { - ($tot, $msgs) = $ibx->search->query("alerts:$i"); - is($tot, 1, "got one result for alerts:$i"); + my $mset = $ibx->search->mset("alerts:$i"); + is($mset->size, 1, "got one result for alerts:$i"); + my $msgs = $ibx->search->mset_to_smsg($ibx, $mset); is($msgs->[0]->{mid}, "a.$i\@b.com", "got expected MID for $i"); } - ($tot, undef) = $ibx->search->query('b:spam'); - is($tot, 1, 'got spam message'); + is($ibx->search->mset('b:spam')->size, 1, 'got spam message'); my $nr = unlink <$maildir/new/*>; is(16, $nr); @@ -108,10 +99,10 @@ EOF } $w->scan('full'); - $config = PublicInbox::Config->new({%orig}); - $ibx = $config->lookup_name($v); - ($tot, undef) = $ibx->search->reopen->query('b:spam'); - is($tot, 0, 'spam removed'); + $cfg = PublicInbox::Config->new(\$orig); + $ibx = $cfg->lookup_name($v); + $ibx->{-no_fsync} = 1; + is($ibx->search->reopen->mset('b:spam')->size, 0, 'spam removed'); is_deeply([], \@warn, 'no warnings'); }