user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/4] watch_maildir: add scan test
Date: Sun, 19 Jun 2016 00:28:45 +0000	[thread overview]
Message-ID: <20160619002847.26685-3-e@80x24.org> (raw)
In-Reply-To: <20160619002847.26685-1-e@80x24.org>

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 <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+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 = <<EOF;
+From: user\@example.com
+To: $addr
+Subject: spam
+Message-Id: <a\@b.com>
+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;

  parent reply	other threads:[~2016-06-19  0:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-19  0:28 [PATCH 0/4] watch improvements for mirroring Eric Wong
2016-06-19  0:28 ` [PATCH 1/4] emergency: avoid needless mkpath dependency Eric Wong
2016-06-19  0:28 ` Eric Wong [this message]
2016-06-19  0:28 ` [PATCH 3/4] watch_maildir: spam removal support Eric Wong
2016-06-19  0:28 ` [PATCH 4/4] import: allow messages without subject Eric Wong
2016-06-19  3:44 ` [PATCH 5/4] watch_maildir: tighten up path checks 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=20160619002847.26685-3-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.
Code repositories for project(s) associated with this public 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).