From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: 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.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 1AD8F2018C for ; Sun, 19 Jun 2016 00:28:50 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/4] watch_maildir: add scan test Date: Sun, 19 Jun 2016 00:28:45 +0000 Message-Id: <20160619002847.26685-3-e@80x24.org> In-Reply-To: <20160619002847.26685-1-e@80x24.org> References: <20160619002847.26685-1-e@80x24.org> List-Id: This should be portable despite the intended use of this directory being non-portable. --- lib/PublicInbox/WatchMaildir.pm | 7 ++++++- t/watch_maildir.t | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 t/watch_maildir.t diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm index 3536375..f1a21b9 100644 --- a/lib/PublicInbox/WatchMaildir.pm +++ b/lib/PublicInbox/WatchMaildir.pm @@ -45,10 +45,14 @@ sub new { }, $class; } +sub _done_for_now { + $_->done foreach values %{$_[0]->{importers}}; +} + sub _try_fsn_paths { my ($self, $paths) = @_; _try_path($self, $_->{path}) foreach @$paths; - $_->done foreach values %{$self->{importers}}; + _done_for_now($self); } sub _try_path { @@ -133,6 +137,7 @@ sub scan { } closedir $dh; } + _done_for_now($self); } 1; diff --git a/t/watch_maildir.t b/t/watch_maildir.t new file mode 100644 index 0000000..6564a86 --- /dev/null +++ b/t/watch_maildir.t @@ -0,0 +1,39 @@ +# Copyright (C) 2016 all contributors +# License: AGPL-3.0+ +use Test::More; +use File::Temp qw/tempdir/; +use Email::MIME; +use PublicInbox::Config; + +my $tmpdir = tempdir('watch_maildir-XXXXXX', TMPDIR => 1, CLEANUP => 1); +my $git_dir = "$tmpdir/test.git"; +my $maildir = "$tmpdir/md"; +use_ok 'PublicInbox::WatchMaildir'; +use_ok 'PublicInbox::Emergency'; +my $cfgpfx = "publicinbox.test"; +my $addr = 'test-public@example.com'; +is(system(qw(git init -q --bare), $git_dir), 0, 'initialized git dir'); + +my $msg = < +Date: Sat, 18 Jun 2016 00:00:00 +0000 + +msg +EOF +PublicInbox::Emergency->new($maildir)->prepare(\$msg); + +my $config = PublicInbox::Config->new({ + "$cfgpfx.address" => $addr, + "$cfgpfx.mainrepo" => $git_dir, + "$cfgpfx.watch" => "maildir:$maildir", +}); + +PublicInbox::WatchMaildir->new($config)->scan; +my $git = PublicInbox::Git->new($git_dir); +my @list = $git->qx(qw(rev-list refs/heads/master)); +is(scalar @list, 1, 'one revision in rev-list'); + +done_testing;