]> Sergey Matveev's repositories - public-inbox.git/commitdiff
v2/ui: get nntpd and init tests running on v2
authorEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Wed, 28 Feb 2018 22:29:38 +0000 (22:29 +0000)
committerEric Wong (Contractor, The Linux Foundation) <e@80x24.org>
Wed, 28 Feb 2018 23:06:20 +0000 (23:06 +0000)
A work-in-progress, but it appears the v2 UI pieces do
will not require a lot of work to do.

lib/PublicInbox/V2Writable.pm
script/public-inbox-init
t/init.t
t/nntpd.t

index 73110ff06df6e1373bbee6ed991062e790843dc3..81c7a4d16c0189902d87fbc052ac4d26e57b1c04 100644 (file)
@@ -79,6 +79,7 @@ sub idx_part {
        $self->{idx_parts}->[$part];
 }
 
+# idempotent
 sub idx_init {
        my ($self) = @_;
        return if $self->{idx_parts};
index 2f33c9efe67d1f689c47c62408efc6b8c3789d5c..f7a60fbb9e829d61e411e0d0c99c9b933abe8d63 100755 (executable)
@@ -6,6 +6,7 @@
 use strict;
 use warnings;
 my $usage = "public-inbox-init NAME GIT_DIR HTTP_URL ADDRESS [ADDRESS..]";
+use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
 use PublicInbox::Config;
 use File::Temp qw/tempfile/;
 use File::Basename qw/dirname/;
@@ -14,9 +15,11 @@ use Cwd qw/abs_path/;
 
 sub x { system(@_) and die join(' ', @_). " failed: $?\n" }
 sub usage { print STDERR "Usage: $usage\n"; exit 1 }
-
+my $version = 1;
+my %opts = ( 'V|version=i' => \$version );
+GetOptions(%opts) or usage();
 my $name = shift @ARGV or usage();
-my $git_dir = shift @ARGV or usage();
+my $mainrepo = shift @ARGV or usage();
 my $http_url = shift @ARGV or usage();
 my (@address) = @ARGV;
 @address or usage();
@@ -25,7 +28,7 @@ my %seen;
 my $pi_config = PublicInbox::Config->default_file;
 my $dir = dirname($pi_config);
 mkpath($dir); # will croak on fatal errors
-my ($fh, $filename) = tempfile('pi-init-XXXXXXXX', DIR => $dir);
+my ($fh, $pi_config_tmp) = tempfile('pi-init-XXXXXXXX', DIR => $dir);
 if (-e $pi_config) {
        open(my $oh, '<', $pi_config) or die "unable to read $pi_config: $!\n";
        my @st = stat($oh);
@@ -62,22 +65,43 @@ if (-e $pi_config) {
 
        exit(1) if $conflict;
 }
-close $fh or die "failed to close $filename: $!\n";
+close $fh or die "failed to close $pi_config_tmp: $!\n";
 
 my $pfx = "publicinbox.$name";
-my @x = (qw/git config/, "--file=$filename");
-$git_dir = abs_path($git_dir);
-x(qw(git init -q --bare), $git_dir);
+my @x = (qw/git config/, "--file=$pi_config_tmp");
+
+$mainrepo = abs_path($mainrepo);
 
-# set a reasonable default:
-x(qw/git config/, "--file=$git_dir/config", 'repack.writeBitmaps', 'true');
+if ($version >= 2) {
+       require PublicInbox::V2Writable;
+       require PublicInbox::Inbox;
+       my $ibx = {
+               mainrepo => $mainrepo,
+               name => $name,
+               version => $version,
+               -primary_address => $address[0],
+       };
+       $ibx = PublicInbox::Inbox->new($ibx);
+       my $v2w = PublicInbox::V2Writable->new($ibx, 1);
+       $v2w->git_init(0);
+       $v2w->idx_init(0);
+       $v2w->done;
+} elsif ($version == 1) {
+       x(qw(git init -q --bare), $mainrepo);
+
+       # set a reasonable default:
+       x(qw/git config/, "--file=$mainrepo/config",
+               'repack.writeBitmaps', 'true');
+} else {
+       die "Unsupported -V/--version: $version\n";
+}
 
 foreach my $addr (@address) {
        next if $seen{lc($addr)};
        x(@x, "--add", "$pfx.address", $addr);
 }
 x(@x, "$pfx.url", $http_url);
-x(@x, "$pfx.mainrepo", $git_dir);
+x(@x, "$pfx.mainrepo", $mainrepo);
 
-rename $filename, $pi_config or
-       die "failed to rename `$filename' to `$pi_config': $!\n";
+rename $pi_config_tmp, $pi_config or
+       die "failed to rename `$pi_config_tmp' to `$pi_config': $!\n";
index 864f1ab572882753e4cc116e50aa49a1eeec4d3a..54b90ec58415778587dfe164259f76f0d96c4133 100644 (file)
--- a/t/init.t
+++ b/t/init.t
@@ -25,4 +25,19 @@ use constant pi_init => 'blib/script/public-inbox-init';
        is((stat($cfgfile))[2] & 07777, 0666, "permissions preserved");
 }
 
+SKIP: {
+       foreach my $mod (qw(DBD::SQLite Search::Xapian::WritableDatabase)) {
+               eval "require $mod";
+               skip "$mod missing for v2", 2 if $@;
+       }
+       local $ENV{PI_DIR} = "$tmpdir/.public-inbox/";
+       my $cfgfile = "$ENV{PI_DIR}/config";
+       my @cmd = (pi_init, '-V2', 'v2list', "$tmpdir/v2list",
+                  qw(http://example.com/v2list v2list@example.com));
+       is(system(@cmd), 0, 'public-inbox-init -V2 OK');
+       ok(-d "$tmpdir/v2list", 'v2list directory exists');
+       ok(-f "$tmpdir/v2list/msgmap.sqlite3", 'msgmap exists');
+       ok(-d "$tmpdir/v2list/all.git", 'catch-all.git directory exists');
+}
+
 done_testing();
index 56b1d604518558e67284580f08076eef6820c4d9..ea0d293947b9d42114d94144a98927ae1ff50c42 100644 (file)
--- a/t/nntpd.t
+++ b/t/nntpd.t
@@ -21,14 +21,18 @@ my $tmpdir = tempdir('pi-nntpd-XXXXXX', TMPDIR => 1, CLEANUP => 1);
 my $home = "$tmpdir/pi-home";
 my $err = "$tmpdir/stderr.log";
 my $out = "$tmpdir/stdout.log";
-my $maindir = "$tmpdir/main.git";
+my $mainrepo = "$tmpdir/main.git";
 my $group = 'test-nntpd';
 my $addr = $group . '@example.com';
 my $nntpd = 'blib/script/public-inbox-nntpd';
 my $init = 'blib/script/public-inbox-init';
 use_ok 'PublicInbox::Import';
+use_ok 'PublicInbox::Inbox';
 use_ok 'PublicInbox::Git';
+use_ok 'PublicInbox::V2Writable';
 
+# XXX FIXME: make it easier to test both versions
+my $version = int($ENV{PI_VERSION} || 1);
 my %opts = (
        LocalAddr => '127.0.0.1',
        ReuseAddr => 1,
@@ -40,14 +44,34 @@ my $sock = IO::Socket::INET->new(%opts);
 my $pid;
 my $len;
 END { kill 'TERM', $pid if defined $pid };
+
+my $ibx = {
+       mainrepo => $mainrepo,
+       name => $group,
+       version => $version,
+       -primary_address => $addr,
+};
+$ibx = PublicInbox::Inbox->new($ibx);
 {
        local $ENV{HOME} = $home;
-       system($init, $group, $maindir, 'http://example.com/', $addr);
+       my @cmd = ($init, $group, $mainrepo, 'http://example.com/', $addr);
+       push @cmd, "-V$version";
+       is(system(@cmd), 0, 'init OK');
        is(system(qw(git config), "--file=$home/.public-inbox/config",
                        "publicinbox.$group.newsgroup", $group),
                0, 'enabled newsgroup');
        my $len;
 
+       my $im;
+       if ($version == 2) {
+               $im = PublicInbox::V2Writable->new($ibx);
+       } elsif ($version == 1) {
+               my $git = PublicInbox::Git->new($mainrepo);
+               $im = PublicInbox::Import->new($git, 'test', $addr);
+       } else {
+               die "unsupported version: $version";
+       }
+
        # ensure successful message delivery
        {
                my $mime = Email::MIME->new(<<EOF);
@@ -66,12 +90,12 @@ EOF
                $list_id =~ s/@/./;
                $mime->header_set('List-Id', "<$list_id>");
                $len = length($mime->as_string);
-               my $git = PublicInbox::Git->new($maindir);
-               my $im = PublicInbox::Import->new($git, 'test', $addr);
                $im->add($mime);
                $im->done;
-               my $s = PublicInbox::SearchIdx->new($maindir, 1);
-               $s->index_sync;
+               if ($version == 1) {
+                       my $s = PublicInbox::SearchIdx->new($mainrepo, 1);
+                       $s->index_sync;
+               }
        }
 
        ok($sock, 'sock created');