X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=t%2Finit.t;h=4bec6a2f31311a66e0ea5777440aec30c67b68e1;hb=7319f5d318a960eeb32a207d226eea7fd9ce2543;hp=6211bb58fba8b12a43cc786255e629c28c51d95d;hpb=8fa5d57855d38f2e6f7e6d9c2eefcbbf0c4d0ac9;p=public-inbox.git diff --git a/t/init.t b/t/init.t index 6211bb58..4bec6a2f 100644 --- a/t/init.t +++ b/t/init.t @@ -1,4 +1,4 @@ -# Copyright (C) 2014-2020 all contributors +# Copyright (C) 2014-2021 all contributors # License: AGPL-3.0+ use strict; use warnings; @@ -6,7 +6,6 @@ use Test::More; 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/" }; @@ -59,10 +92,25 @@ sub quiet_fail { like($err, qr/`\\n' not allowed in `/s, 'reported \\n'); is_deeply([glob("$tmpdir/.public-inbox/pi-init-*")], [], 'no junk files left behind'); + + # "git init" does this, too + $cmd = [ '-init', 'deep-non-existent', "$tmpdir/a/b/c/d", + qw(http://example.com/abcd abcd@example.com) ]; + $err = ''; + ok(run_script($cmd, $env, $rdr), 'initializes non-existent hierarchy'); + ok(-d "$tmpdir/a/b/c/d", 'directory created'); + is(PublicInbox::Inbox::try_cat("$tmpdir/a/b/c/d/description"), + "public inbox for abcd\@example.com\n", 'description set'); + + open my $fh, '>', "$tmpdir/d" or BAIL_OUT "open: $!"; + close $fh; + $cmd = [ '-init', 'd-f-conflict', "$tmpdir/d/f/conflict", + qw(http://example.com/conflict onflict@example.com) ]; + ok(!run_script($cmd, $env, $rdr), 'fails on D/F conflict'); } SKIP: { - require_mods(qw(DBD::SQLite Search::Xapian::WritableDatabase), 2); + require_mods(qw(DBD::SQLite Search::Xapian), 2); require_git(2.6, 1) or skip "git 2.6+ required", 2; use_ok 'PublicInbox::Msgmap'; local $ENV{PI_DIR} = "$tmpdir/.public-inbox/"; @@ -95,6 +143,20 @@ SKIP: { my $ibx = PublicInbox::Inbox->new({ inboxdir => $dir }); is(PublicInbox::Admin::detect_indexlevel($ibx), $lvl, 'detected expected level w/o config'); + ok(!$ibx->{-skip_docdata}, 'docdata written by default'); + } + for my $v (1, 2) { + my $name = "v$v-skip-docdata"; + my $dir = "$tmpdir/$name"; + $cmd = [ '-init', $name, "-V$v", '--skip-docdata', + $dir, "http://example.com/$name", + "$name\@example.com" ]; + ok(run_script($cmd), "-init -V$v --skip-docdata"); + my $ibx = PublicInbox::Inbox->new({ inboxdir => $dir }); + is(PublicInbox::Admin::detect_indexlevel($ibx), 'full', + "detected default indexlevel -V$v"); + ok($ibx->{-skip_docdata}, "docdata skip set -V$v"); + ok($ibx->search->has_threadid, 'has_threadid flag set on new inbox'); } # loop for idempotency @@ -116,7 +178,7 @@ SKIP: { 'publicinboxmda.spamcheck', 'none') == 0 or BAIL_OUT "git config $?"; my $addr = 'skip3@example.com'; - $cmd = [ qw(-init -V2 -Lbasic -N12 skip3), "$tmpdir/skip3", + $cmd = [ qw(-init -V2 -Lbasic --skip-artnum=12 skip3), "$tmpdir/skip3", qw(http://example.com/skip3), $addr ]; ok(run_script($cmd), '--skip-artnum -V2'); my $env = { ORIGINAL_RECIPIENT => $addr }; @@ -131,13 +193,14 @@ SKIP: { $addr = 'skip4@example.com'; $env = { ORIGINAL_RECIPIENT => $addr }; - $cmd = [ qw(-init -V1 -N12 -Lmedium skip4), "$tmpdir/skip4", + $cmd = [ qw(-init -V1 --skip-artnum 12 -Lmedium skip4), "$tmpdir/skip4", qw(http://example.com/skip4), $addr ]; ok(run_script($cmd), '--skip-artnum -V1'); $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'); }