about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-06-27 10:03:54 +0000
committerEric Wong <e@yhbt.net>2020-06-28 22:28:46 +0000
commitb85909064e7209de45680150b5fb457736fa618d (patch)
tree0b8cfe274872b4dd14edbd587fd0fe6005df764b /t
parenta3e57ebf3192885b1928de33c4e07b88f724b052 (diff)
downloadpublic-inbox-b85909064e7209de45680150b5fb457736fa618d.tar.gz
This is similar to IMAP support, but only supports polling.
Automatic altid support is not yet supported, yet; but may
be in the future.

v2: small grammar fix by Kyle Meyer
Link: https://public-inbox.org/meta/87sgeg5nxf.fsf@kyleam.com/
Diffstat (limited to 't')
-rw-r--r--t/nntpd.t52
-rw-r--r--t/watch_nntp.t15
2 files changed, 67 insertions, 0 deletions
diff --git a/t/nntpd.t b/t/nntpd.t
index 9d0ee2ba..d72d6a1c 100644
--- a/t/nntpd.t
+++ b/t/nntpd.t
@@ -352,6 +352,7 @@ Date: Fri, 02 Oct 1993 00:00:00 +0000
                 my @of = xqx([$lsof, '-p', $td->{pid}], undef, $noerr);
                 is(scalar(grep(/\(deleted\)/, @of)), 0, 'no deleted files');
         };
+        SKIP: { test_watch($tmpdir, $sock, $group) };
         {
                 setsockopt($s, IPPROTO_TCP, TCP_NODELAY, 1);
                 syswrite($s, 'HDR List-id 1-');
@@ -391,4 +392,55 @@ sub read_til_dot {
         $buf;
 }
 
+sub test_watch {
+        my ($tmpdir, $sock, $group) = @_;
+        use_ok 'PublicInbox::WatchMaildir';
+        use_ok 'PublicInbox::InboxIdle';
+        require_git('1.8.5', 1) or skip('git 1.8.5+ needed for --urlmatch', 4);
+        my $old_env = { HOME => $ENV{HOME} };
+        my $home = "$tmpdir/watch_home";
+        mkdir $home or BAIL_OUT $!;
+        mkdir "$home/.public-inbox" or BAIL_OUT $!;
+        local $ENV{HOME} = $home;
+        my $name = 'watchnntp';
+        my $addr = "i1\@example.com";
+        my $url = "http://example.com/i1";
+        my $inboxdir = "$tmpdir/watchnntp";
+        my $cmd = ['-init', '-V1', '-Lbasic', $name, $inboxdir, $url, $addr];
+        my ($ihost, $iport) = ($sock->sockhost, $sock->sockport);
+        my $nntpurl = "nntp://$ihost:$iport/$group";
+        run_script($cmd) or BAIL_OUT("init $name");
+        xsys(qw(git config), "--file=$home/.public-inbox/config",
+                        "publicinbox.$name.watch",
+                        $nntpurl) == 0 or BAIL_OUT "git config $?";
+        # try again with polling
+        xsys(qw(git config), "--file=$home/.public-inbox/config",
+                'nntp.PollInterval', 0.11) == 0
+                or BAIL_OUT "git config $?";
+        my $cfg = PublicInbox::Config->new;
+        PublicInbox::DS->Reset;
+        my $ii = PublicInbox::InboxIdle->new($cfg);
+        my $cb = sub { PublicInbox::DS->SetPostLoopCallback(sub {}) };
+        my $obj = bless \$cb, 'PublicInbox::TestCommon::InboxWakeup';
+        $cfg->each_inbox(sub { $_[0]->subscribe_unlock('ident', $obj) });
+        my $watcherr = "$tmpdir/watcherr";
+        open my $err_wr, '>', $watcherr or BAIL_OUT $!;
+        open my $err, '<', $watcherr or BAIL_OUT $!;
+        my $w = start_script(['-watch'], undef, { 2 => $err_wr });
+
+        diag 'waiting for initial fetch...';
+        PublicInbox::DS->EventLoop;
+        diag 'inbox unlocked on initial fetch';
+        $w->kill;
+        $w->join;
+        is($?, 0, 'no error in exited -watch process');
+        $cfg->each_inbox(sub { shift->unsubscribe_unlock('ident') });
+        $ii->close;
+        PublicInbox::DS->Reset;
+        my @err = grep(!/^I:/, <$err>);
+        is(@err, 0, 'no warnings/errors from -watch'.join(' ', @err));
+        my @ls = xqx(['git', "--git-dir=$inboxdir", qw(ls-tree -r HEAD)]);
+        isnt(scalar(@ls), 0, 'imported something');
+}
+
 1;
diff --git a/t/watch_nntp.t b/t/watch_nntp.t
new file mode 100644
index 00000000..f919930e
--- /dev/null
+++ b/t/watch_nntp.t
@@ -0,0 +1,15 @@
+# Copyright (C) 2020 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use strict;
+use Test::More;
+use PublicInbox::Config;
+# see t/nntpd*.t for tests against a live NNTP server
+
+use_ok 'PublicInbox::WatchMaildir';
+my $nntp_url = \&PublicInbox::WatchMaildir::nntp_url;
+is('news://example.com/inbox.foo',
+        $nntp_url->('NEWS://examplE.com/inbox.foo'), 'lowercased');
+is('snews://example.com/inbox.foo',
+        $nntp_url->('nntps://example.com/inbox.foo'), 'nntps:// is snews://');
+
+done_testing;