]> Sergey Matveev's repositories - public-inbox.git/blob - t/config.t
50bc8d6d3eefb729417750a5721a9ddb1380a496
[public-inbox.git] / t / config.t
1 # Copyright (C) 2014, Eric Wong <normalperson@yhbt.net> and all contributors
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(CLEANUP => 1);
9
10 {
11         is(system(qw(git init -q --bare), $tmpdir), 0, "git init successful");
12         {
13                 local $ENV{GIT_DIR} = $tmpdir;
14                 is(system(qw(git config foo.bar hihi)), 0, "set config");
15         }
16
17         my $tmp = PublicInbox::Config->new("$tmpdir/config");
18
19         is("hihi", $tmp->{"foo.bar"}, "config read correctly");
20         is("true", $tmp->{"core.bare"}, "used --bare repo");
21 }
22
23 {
24         my $f = "examples/public-inbox-config";
25         ok(-r $f, "$f is readable");
26
27         my $cfg = PublicInbox::Config->new($f);
28         is_deeply($cfg->lookup('meta@public-inbox.org'), {
29                 'mainrepo' => '/home/pi/meta-main.git',
30                 'address' => 'meta@public-inbox.org',
31                 -primary_address => 'meta@public-inbox.org',
32                 'description' => 'development discussion',
33                 'listname' => 'meta',
34         }, "lookup matches expected output");
35
36         is($cfg->lookup('blah@example.com'), undef,
37                 "non-existent lookup returns undef");
38
39         my $test = $cfg->lookup('test@public-inbox.org');
40         is_deeply($test, {
41                 'address' => ['try@public-inbox.org',
42                               'sandbox@public-inbox.org',
43                               'test@public-inbox.org'],
44                 -primary_address => 'try@public-inbox.org',
45                 'mainrepo' => '/home/pi/test-main.git',
46                 'description' => 'test/sandbox area, occasionally reset',
47                 'listname' => 'test',
48         }, "lookup matches expected output for test");
49 }
50
51 done_testing();