]> Sergey Matveev's repositories - public-inbox.git/blobdiff - t/init.t
No ext_urls
[public-inbox.git] / t / init.t
index d46bef234b2f2d52376cc7a35c0bf2394371b75e..46258e45df4c733d7f52c164331ac3158d64c623 100644 (file)
--- a/t/init.t
+++ b/t/init.t
@@ -1,12 +1,11 @@
-# Copyright (C) 2014-2021 all contributors <meta@public-inbox.org>
+#!perl -w
+# Copyright (C) all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 use strict;
-use warnings;
-use Test::More;
+use v5.10.1;
 use PublicInbox::Config;
 use PublicInbox::TestCommon;
 use PublicInbox::Admin;
-use File::Basename;
 my ($tmpdir, $for_destroy) = tmpdir();
 sub quiet_fail {
        my ($cmd, $msg) = @_;
@@ -48,6 +47,40 @@ sub quiet_fail {
        is($? >> 8, 255, 'got expected exit code on lock failure');
        ok(unlink("$cfgfile.lock"),
                '-init did not unlink lock on failure');
+
+       my @init_args = ('i', "$tmpdir/i",
+                  qw(http://example.com/i i@example.com));
+       $cmd = [ qw(-init -c .bogus=val), @init_args ];
+       quiet_fail($cmd, 'invalid -c KEY=VALUE fails');
+       $cmd = [ qw(-init -c .bogus=val), @init_args ];
+       quiet_fail($cmd, '-c KEY-only fails');
+       $cmd = [ qw(-init -c address=clist@example.com), @init_args ];
+       quiet_fail($cmd, '-c address=CONFLICTING-VALUE fails');
+
+       $cmd = [ qw(-init -c no=problem -c no=problemo), @init_args ];
+       ok(run_script($cmd), '-c KEY=VALUE runs');
+       my $env = { GIT_CONFIG => "$ENV{PI_DIR}/config" };
+       chomp(my @v = xqx([qw(git config --get-all publicinbox.i.no)], $env));
+       is_deeply(\@v, [ qw(problem problemo) ]) or xbail(\@v);
+
+       ok(run_script($cmd), '-c KEY=VALUE runs idempotently');
+       chomp(my @v2 = xqx([qw(git config --get-all publicinbox.i.no)], $env));
+       is_deeply(\@v, \@v2, 'nothing repeated') or xbail(\@v2);
+
+       ok(run_script([@$cmd, '-c', 'no=more']), '-c KEY=VALUE addendum');
+       chomp(@v = xqx([qw(git config --get-all publicinbox.i.no)], $env));
+       is_deeply(\@v, [ qw(problem problemo more) ]) or xbail(\@v);
+
+
+       ok(run_script([@$cmd, '-c', 'no=problem']), '-c KEY=VALUE repeated');
+       chomp(@v = xqx([qw(git config --get-all publicinbox.i.no)], $env));
+       is_deeply(\@v, [ qw(problem problemo more) ]) or xbail(\@v);
+
+       ok(run_script([@$cmd, '-c', 'address=j@example.com']),
+               '-c KEY=VALUE address');
+       chomp(@v = xqx([qw(git config --get-all publicinbox.i.address)], $env));
+       is_deeply(\@v, [ qw(i@example.com j@example.com) ],
+               'extra address added via -c KEY=VALUE');
 }
 {
        my $env = { PI_DIR => "$tmpdir/.public-inbox/" };
@@ -64,8 +97,17 @@ sub quiet_fail {
        $cmd = [ '-init', 'deep-non-existent', "$tmpdir/a/b/c/d",
                   qw(http://example.com/abcd abcd@example.com) ];
        $err = '';
+       my $umask = umask(022) // xbail "umask: $!";
        ok(run_script($cmd, $env, $rdr), 'initializes non-existent hierarchy');
+       umask($umask) // xbail "umask: $!";
        ok(-d "$tmpdir/a/b/c/d", 'directory created');
+       my $desc = "$tmpdir/a/b/c/d/description";
+       is(PublicInbox::Git::try_cat($desc),
+               "public inbox for abcd\@example.com\n", 'description set');
+       my $mode = (stat($desc))[2];
+       is(sprintf('0%03o', $mode & 0777), '0644',
+               'description respects umask');
+
        open my $fh, '>', "$tmpdir/d" or BAIL_OUT "open: $!";
        close $fh;
        $cmd = [ '-init', 'd-f-conflict', "$tmpdir/d/f/conflict",
@@ -75,7 +117,7 @@ sub quiet_fail {
 
 SKIP: {
        require_mods(qw(DBD::SQLite Search::Xapian), 2);
-       require_git(2.6, 1) or skip "git 2.6+ required", 2;
+       require_git(2.6, 2);
        use_ok 'PublicInbox::Msgmap';
        local $ENV{PI_DIR} = "$tmpdir/.public-inbox/";
        local $ENV{PI_EMERGENCY} = "$tmpdir/.public-inbox/emergency";
@@ -163,7 +205,8 @@ SKIP: {
        $err = '';
        ok(run_script([qw(-mda --no-precheck)], $env, $rdr), 'deliver V1');
        diag "err=$err" if $err;
-       $mm = PublicInbox::Msgmap->new("$tmpdir/skip4");
+       $mm = PublicInbox::Msgmap->new_file(
+                       "$tmpdir/skip4/public-inbox/msgmap.sqlite3");
        $n = $mm->num_for($mid);
        is($n, 13, 'V1 NNTP article numbers skipped via --skip-artnum');
 }