1 # Copyright (C) 2014-2015 all contributors <meta@public-inbox.org>
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
6 use PublicInbox::Config;
7 use File::Temp qw/tempdir/;
8 my $tmpdir = tempdir('pi-config-XXXXXX', TMPDIR => 1, CLEANUP => 1);
11 is(system(qw(git init -q --bare), $tmpdir), 0, "git init successful");
12 my @cmd = ('git', "--git-dir=$tmpdir", qw(config foo.bar hihi));
13 is(system(@cmd), 0, "set config");
15 my $tmp = PublicInbox::Config->new("$tmpdir/config");
17 is("hihi", $tmp->{"foo.bar"}, "config read correctly");
18 is("true", $tmp->{"core.bare"}, "used --bare repo");
22 my $f = "examples/public-inbox-config";
23 ok(-r $f, "$f is readable");
25 my $cfg = PublicInbox::Config->new($f);
26 is_deeply($cfg->lookup('meta@public-inbox.org'), {
27 'mainrepo' => '/home/pi/meta-main.git',
28 'address' => 'meta@public-inbox.org',
29 'domain' => 'public-inbox.org',
30 'url' => 'http://example.com/meta',
31 -primary_address => 'meta@public-inbox.org',
35 }, "lookup matches expected output");
37 is($cfg->lookup('blah@example.com'), undef,
38 "non-existent lookup returns undef");
40 my $test = $cfg->lookup('test@public-inbox.org');
42 'address' => ['try@public-inbox.org',
43 'sandbox@public-inbox.org',
44 'test@public-inbox.org'],
45 -primary_address => 'try@public-inbox.org',
46 'mainrepo' => '/home/pi/test-main.git',
47 'domain' => 'public-inbox.org',
50 'url' => 'http://example.com/test',
52 }, "lookup matches expected output for test");
57 my $cfgpfx = "publicinbox.test";
58 my @altid = qw(serial:gmane:file=a serial:enamg:file=b);
59 my $config = PublicInbox::Config->new({
60 "$cfgpfx.address" => 'test@example.com',
61 "$cfgpfx.mainrepo" => '/path/to/non/existent',
62 "$cfgpfx.altid" => [ @altid ],
64 my $ibx = $config->lookup_name('test');
65 is_deeply($ibx->{altid}, [ @altid ]);