]> Sergey Matveev's repositories - public-inbox.git/blob - t/config.t
config: assume lists have multiple addresses
[public-inbox.git] / t / config.t
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)
3 use strict;
4 use warnings;
5 use Test::More;
6 use PublicInbox::Config;
7 use File::Temp qw/tempdir/;
8 my $tmpdir = tempdir('pi-config-XXXXXX', TMPDIR => 1, CLEANUP => 1);
9
10 {
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");
14
15         my $tmp = PublicInbox::Config->new("$tmpdir/config");
16
17         is("hihi", $tmp->{"foo.bar"}, "config read correctly");
18         is("true", $tmp->{"core.bare"}, "used --bare repo");
19 }
20
21 {
22         my $f = "examples/public-inbox-config";
23         ok(-r $f, "$f is readable");
24
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',
32                 'name' => 'meta',
33                 feedmax => 25,
34                 -httpbackend_limiter => undef,
35                 nntpserver => undef,
36         }, "lookup matches expected output");
37
38         is($cfg->lookup('blah@example.com'), undef,
39                 "non-existent lookup returns undef");
40
41         my $test = $cfg->lookup('test@public-inbox.org');
42         is_deeply($test, {
43                 'address' => ['try@public-inbox.org',
44                               'sandbox@public-inbox.org',
45                               'test@public-inbox.org'],
46                 -primary_address => 'try@public-inbox.org',
47                 'mainrepo' => '/home/pi/test-main.git',
48                 'domain' => 'public-inbox.org',
49                 'name' => 'test',
50                 feedmax => 25,
51                 'url' => 'http://example.com/test',
52                 -httpbackend_limiter => undef,
53                 nntpserver => undef,
54         }, "lookup matches expected output for test");
55 }
56
57
58 {
59         my $cfgpfx = "publicinbox.test";
60         my @altid = qw(serial:gmane:file=a serial:enamg:file=b);
61         my $config = PublicInbox::Config->new({
62                 "$cfgpfx.address" => 'test@example.com',
63                 "$cfgpfx.mainrepo" => '/path/to/non/existent',
64                 "$cfgpfx.altid" => [ @altid ],
65         });
66         my $ibx = $config->lookup_name('test');
67         is_deeply($ibx->{altid}, [ @altid ]);
68 }
69
70 {
71         my $pfx = "publicinbox.test";
72         my %h = (
73                 "$pfx.address" => 'test@example.com',
74                 "$pfx.mainrepo" => '/path/to/non/existent',
75                 "publicinbox.nntpserver" => 'news.example.com',
76         );
77         my %tmp = %h;
78         my $cfg = PublicInbox::Config->new(\%tmp);
79         my $ibx = $cfg->lookup_name('test');
80         is($ibx->{nntpserver}, 'news.example.com', 'global NNTP server');
81
82         delete $h{'publicinbox.nntpserver'};
83         $h{"$pfx.nntpserver"} = 'news.alt.example.com';
84         $cfg = PublicInbox::Config->new(\%h);
85         $ibx = $cfg->lookup_name('test');
86         is($ibx->{nntpserver}, 'news.alt.example.com','per-inbox NNTP server');
87 }
88
89 done_testing();