1 # Copyright (C) 2019-2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::TestCommon;
7 use PublicInbox::Import;
8 use_ok 'PublicInbox::Admin', qw(resolve_repo_dir);
9 my ($tmpdir, $for_destroy) = tmpdir();
10 my $git_dir = "$tmpdir/v1";
11 my $v2_dir = "$tmpdir/v2";
14 PublicInbox::Import::init_bare($git_dir);
17 is(resolve_repo_dir($git_dir), $git_dir, 'top-level GIT_DIR resolved');
18 is(resolve_repo_dir("$git_dir/objects"), $git_dir, 'GIT_DIR/objects resolved');
20 ok(chdir($git_dir), 'chdir GIT_DIR works');
21 is(resolve_repo_dir(), $git_dir, 'resolve_repo_dir works in GIT_DIR');
23 ok(chdir("$git_dir/objects"), 'chdir GIT_DIR/objects works');
24 is(resolve_repo_dir(), $git_dir, 'resolve_repo_dir works in GIT_DIR');
25 $res = resolve_repo_dir(undef, \$v);
26 is($v, 1, 'version 1 detected');
27 is($res, $git_dir, 'detects directory along with version');
29 # $tmpdir could be inside a git working, directory, so we test '/'
32 # do people version-control "/"?
33 skip "$no_vcs_dir is version controlled by git", 4 if -d '/.git';
34 open my $null, '>', '/dev/null' or die "open /dev/null: $!";
35 open my $olderr, '>&', \*STDERR or die "dup stderr: $!";
37 ok(chdir($no_vcs_dir), 'chdir to a non-inbox');
38 open STDERR, '>&', $null or die "redirect stderr to /dev/null: $!";
39 $res = eval { resolve_repo_dir() };
40 open STDERR, '>&', $olderr or die "restore stderr: $!";
41 is($res, undef, 'fails inside non-version-controlled dir');
43 ok(chdir($tmpdir), 'back to test-specific $tmpdir');
44 open STDERR, '>&', $null or die "redirect stderr to /dev/null: $!";
45 $res = eval { resolve_repo_dir($no_vcs_dir) };
47 open STDERR, '>&', $olderr or die "restore stderr: $!";
48 is($res, undef, 'fails on non-version-controlled dir');
49 ok($err, '$@ set on failure');
54 for my $m (qw(DBD::SQLite)) {
55 skip "$m missing", 5 unless eval "require $m";
57 use_ok 'PublicInbox::V2Writable';
58 use_ok 'PublicInbox::Inbox';
59 my $ibx = PublicInbox::Inbox->new({
61 name => 'test-v2writable',
63 -primary_address => 'test@example.com',
64 indexlevel => 'basic',
66 PublicInbox::V2Writable->new($ibx, 1)->idx_init;
68 ok(-e "$v2_dir/inbox.lock", 'exists');
69 is(resolve_repo_dir($v2_dir), $v2_dir,
70 'resolve_repo_dir works on v2_dir');
71 ok(chdir($v2_dir), 'chdir v2_dir OK');
72 is(resolve_repo_dir(), $v2_dir, 'resolve_repo_dir works inside v2_dir');
73 $res = resolve_repo_dir(undef, \$v);
74 is($v, 2, 'version 2 detected');
75 is($res, $v2_dir, 'detects directory along with version');
77 # TODO: should work from inside Xapian dirs, and git dirs, here...
85 '1500K' => 1500 * 1024,
86 '15m' => 15 * (1024 ** 2),
90 my ($in, $out) = splice(@pairs, 0, 2);
92 ok(PublicInbox::Admin::parse_unsigned(\$in), "parse_unsigned $orig");
93 is($in, $out, "got $orig => ($in == $out)");
96 for my $v ('', 'bogus', '1p', '1gig') {
97 ok(!PublicInbox::Admin::parse_unsigned(\$v),
98 "parse_unsigned rejects $v");