summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
53a8e32)
Rewrite a bunch of tests to use ordered input (emulating
"git config -l" output) so we can always walk sections in
the order they were given in the config file.
14 files changed:
sub new {
my ($class, $file) = @_;
$file = default_file() unless defined($file);
sub new {
my ($class, $file) = @_;
$file = default_file() unless defined($file);
- $file = ref $file ? $file : git_config_dump($file);
- my $self = bless $file, $class;
-
+ my $self;
+ if (ref($file) eq 'SCALAR') { # used by some tests
+ open my $fh, '<', $file or die; # PerlIO::scalar
+ $self = config_fh_parse($fh, "\n", '=');
+ } else {
+ $self = git_config_dump($file);
+ }
+ bless $self, $class;
# caches
$self->{-by_addr} ||= {};
$self->{-by_list_id} ||= {};
# caches
$self->{-by_addr} ||= {};
$self->{-by_list_id} ||= {};
sub each_inbox {
my ($self, $cb) = @_;
sub each_inbox {
my ($self, $cb) = @_;
- if (my $section_order = $self->{-section_order}) {
- foreach my $section (@$section_order) {
- next if $section !~ m!\Apublicinbox\.([^/]+)\z!;
- $self->{"publicinbox.$1.mainrepo"} or next;
- my $ibx = lookup_name($self, $1) or next;
- $cb->($ibx);
- }
- } else {
- my %seen;
- foreach my $k (keys %$self) {
- $k =~ m!\Apublicinbox\.([^/]+)\.mainrepo\z! or next;
- next if $seen{$1};
- $seen{$1} = 1;
- my $ibx = lookup_name($self, $1) or next;
- $cb->($ibx);
- }
+ # may auto-vivify if config file is non-existent:
+ foreach my $section (@{$self->{-section_order}}) {
+ next if $section !~ m!\Apublicinbox\.([^/]+)\z!;
+ $self->{"publicinbox.$1.mainrepo"} or next;
+ my $ibx = lookup_name($self, $1) or next;
+ $cb->($ibx);
config_dir() . '/config';
}
config_dir() . '/config';
}
-sub git_config_dump {
- my ($file) = @_;
- my (%section_seen, @section_order);
- return {} unless -e $file;
- my @cmd = (qw/git config -z -l/, "--file=$file");
- my $cmd = join(' ', @cmd);
- my $fh = popen_rd(\@cmd) or die "popen_rd failed for $file: $!\n";
+sub config_fh_parse ($$$) {
+ my ($fh, $rs, $fs) = @_;
+ my (%section_seen, @section_order);
+ local $/ = $rs;
while (defined(my $line = <$fh>)) {
chomp $line;
while (defined(my $line = <$fh>)) {
chomp $line;
- my ($k, $v) = split(/\n/, $line, 2);
-
+ my ($k, $v) = split($fs, $line, 2);
my ($section) = ($k =~ /\A(\S+)\.[^\.]+\z/);
unless (defined $section_seen{$section}) {
$section_seen{$section} = 1;
my ($section) = ($k =~ /\A(\S+)\.[^\.]+\z/);
unless (defined $section_seen{$section}) {
$section_seen{$section} = 1;
- close $fh or die "failed to close ($cmd) pipe: $?";
$rv{-section_order} = \@section_order;
\%rv;
}
$rv{-section_order} = \@section_order;
\%rv;
}
+sub git_config_dump {
+ my ($file) = @_;
+ return {} unless -e $file;
+ my @cmd = (qw/git config -z -l/, "--file=$file");
+ my $cmd = join(' ', @cmd);
+ my $fh = popen_rd(\@cmd) or die "popen_rd failed for $file: $!\n";
+ my $rv = config_fh_parse($fh, "\0", "\n");
+ close $fh or die "failed to close ($cmd) pipe: $?";
+ $rv;
+}
+
sub valid_inbox_name ($) {
my ($name) = @_;
sub valid_inbox_name ($) {
my ($name) = @_;
{
my $cfgpfx = "publicinbox.test";
my @altid = qw(serial:gmane:file=a serial:enamg:file=b);
{
my $cfgpfx = "publicinbox.test";
my @altid = qw(serial:gmane:file=a serial:enamg:file=b);
- my $config = PublicInbox::Config->new({
- "$cfgpfx.address" => 'test@example.com',
- "$cfgpfx.mainrepo" => '/path/to/non/existent',
- "$cfgpfx.altid" => [ @altid ],
- });
+ my $config = PublicInbox::Config->new(\<<EOF);
+$cfgpfx.address=test\@example.com
+$cfgpfx.mainrepo=/path/to/non/existent
+$cfgpfx.altid=serial:gmane:file=a
+$cfgpfx.altid=serial:enamg:file=b
+EOF
my $ibx = $config->lookup_name('test');
is_deeply($ibx->{altid}, [ @altid ]);
}
{
my $pfx = "publicinbox.test";
my $ibx = $config->lookup_name('test');
is_deeply($ibx->{altid}, [ @altid ]);
}
{
my $pfx = "publicinbox.test";
- my %h = (
- "$pfx.address" => 'test@example.com',
- "$pfx.mainrepo" => '/path/to/non/existent',
- "publicinbox.nntpserver" => 'news.example.com',
- );
- my %tmp = %h;
- my $cfg = PublicInbox::Config->new(\%tmp);
+ my $str = <<EOF;
+$pfx.address=test\@example.com
+$pfx.mainrepo=/path/to/non/existent
+publicinbox.nntpserver=news.example.com
+EOF
+ my $cfg = PublicInbox::Config->new(\$str);
my $ibx = $cfg->lookup_name('test');
is($ibx->{nntpserver}, 'news.example.com', 'global NNTP server');
my $ibx = $cfg->lookup_name('test');
is($ibx->{nntpserver}, 'news.example.com', 'global NNTP server');
- delete $h{'publicinbox.nntpserver'};
- $h{"$pfx.nntpserver"} = 'news.alt.example.com';
- $cfg = PublicInbox::Config->new(\%h);
+ $str = <<EOF;
+$pfx.address=test\@example.com
+$pfx.mainrepo=/path/to/non/existent
+$pfx.nntpserver=news.alt.example.com
+EOF
+ $cfg = PublicInbox::Config->new(\$str);
$ibx = $cfg->lookup_name('test');
is($ibx->{nntpserver}, 'news.alt.example.com','per-inbox NNTP server');
}
$ibx = $cfg->lookup_name('test');
is($ibx->{nntpserver}, 'news.alt.example.com','per-inbox NNTP server');
}
{
my $pfx = "publicinbox.test";
my $pfx2 = "publicinbox.foo";
{
my $pfx = "publicinbox.test";
my $pfx2 = "publicinbox.foo";
- my %h = (
- "$pfx.address" => 'test@example.com',
- "$pfx.mainrepo" => '/path/to/non/existent',
- "$pfx2.address" => 'foo@example.com',
- "$pfx2.mainrepo" => '/path/to/foo',
- lc("publicinbox.noObfuscate") =>
- 'public-inbox.org @example.com z@EXAMPLE.com',
- "$pfx.obfuscate" => 'true', # :<
- );
- my %tmp = %h;
- my $cfg = PublicInbox::Config->new(\%tmp);
+ my $str = <<EOF;
+$pfx.address=test\@example.com
+$pfx.mainrepo=/path/to/non/existent
+$pfx2.address=foo\@example.com
+$pfx2.mainrepo=/path/to/foo
+publicinbox.noobfuscate=public-inbox.org \@example.com z\@EXAMPLE.com
+$pfx.obfuscate=true
+EOF
+ my $cfg = PublicInbox::Config->new(\$str);
my $ibx = $cfg->lookup_name('test');
my $re = $ibx->{-no_obfuscate_re};
like('meta@public-inbox.org', $re,
my $ibx = $cfg->lookup_name('test');
my $re = $ibx->{-no_obfuscate_re};
like('meta@public-inbox.org', $re,
{
my $pfx1 = "publicinbox.test1";
my $pfx2 = "publicinbox.test2";
{
my $pfx1 = "publicinbox.test1";
my $pfx2 = "publicinbox.test2";
- my $h = {
- "$pfx1.address" => 'test@example.com',
- "$pfx1.mainrepo" => '/path/to/non/existent',
- "$pfx2.address" => 'foo@example.com',
- "$pfx2.mainrepo" => '/path/to/foo',
- "$pfx1.coderepo" => 'project',
- "$pfx2.coderepo" => 'project',
- "coderepo.project.dir" => '/path/to/project.git',
- };
- my $cfg = PublicInbox::Config->new($h);
+ my $str = <<EOF;
+$pfx1.address=test\@example.com
+$pfx1.mainrepo=/path/to/non/existent
+$pfx2.address=foo\@example.com
+$pfx2.mainrepo=/path/to/foo
+$pfx1.coderepo=project
+$pfx2.coderepo=project
+coderepo.project.dir=/path/to/project.git
+EOF
+ my $cfg = PublicInbox::Config->new(\$str);
my $t1 = $cfg->lookup_name('test1');
my $t2 = $cfg->lookup_name('test2');
is($t1->{-repo_objs}->[0], $t2->{-repo_objs}->[0],
my $t1 = $cfg->lookup_name('test1');
my $t2 = $cfg->lookup_name('test2');
is($t1->{-repo_objs}->[0], $t2->{-repo_objs}->[0],
use PublicInbox::Config;
my $cfgpfx = "publicinbox.test";
{
use PublicInbox::Config;
my $cfgpfx = "publicinbox.test";
{
- my $config = PublicInbox::Config->new({
- "$cfgpfx.address" => 'test@example.com',
- "$cfgpfx.mainrepo" => '/path/to/non/existent',
- "$cfgpfx.httpbackendmax" => 12,
- });
+ my $config = PublicInbox::Config->new(\<<EOF);
+$cfgpfx.address=test\@example.com
+$cfgpfx.mainrepo=/path/to/non/existent
+$cfgpfx.httpbackendmax=12
+EOF
my $ibx = $config->lookup_name('test');
my $git = $ibx->git;
my $old = "$git";
my $ibx = $config->lookup_name('test');
my $git = $ibx->git;
my $old = "$git";
- my $config = PublicInbox::Config->new({
- 'publicinboxlimiter.named.max' => 3,
- "$cfgpfx.address" => 'test@example.com',
- "$cfgpfx.mainrepo" => '/path/to/non/existent',
- "$cfgpfx.httpbackendmax" => 'named',
- });
+ my $config = PublicInbox::Config->new(\<<EOF);
+publicinboxlimiter.named.max=3
+$cfgpfx.address=test\@example.com
+$cfgpfx.mainrepo=/path/to/non/existent
+$cfgpfx.httpbackendmax=named
+EOF
my $ibx = $config->lookup_name('test');
my $git = $ibx->git;
ok($git, 'got git object');
my $ibx = $config->lookup_name('test');
my $git = $ibx->git;
ok($git, 'got git object');
+ my $old = "$git"; # stringify object ref "Git(0xDEADBEEF)"
my $lim = $git->{-httpbackend_limiter};
ok($lim, 'Limiter exists');
is($lim->{max}, 3, 'limiter has expected slots');
my $lim = $git->{-httpbackend_limiter};
ok($lim, 'Limiter exists');
is($lim->{max}, 3, 'limiter has expected slots');
use PublicInbox::WWW;
use_ok 'PublicInbox::WwwAttach';
use Plack::Builder;
use PublicInbox::WWW;
use_ok 'PublicInbox::WwwAttach';
use Plack::Builder;
-my $config = PublicInbox::Config->new({
- "$cfgpfx.address" => $addr,
- "$cfgpfx.mainrepo" => $maindir,
-});
+my $config = PublicInbox::Config->new(\<<EOF);
+$cfgpfx.address=$addr
+$cfgpfx.mainrepo=$maindir
+EOF
is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
my $git = PublicInbox::Git->new($maindir);
my $im = PublicInbox::Import->new($git, 'test', $addr);
is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
my $git = PublicInbox::Git->new($maindir);
my $im = PublicInbox::Import->new($git, 'test', $addr);
-my $cfg = {
- "$cfgpfx.address" => $ibx->{-primary_address},
- "$cfgpfx.mainrepo" => $mainrepo,
-};
-my $config = PublicInbox::Config->new($cfg);
+my $cfg = <<EOF;
+$cfgpfx.address=$ibx->{-primary_address}
+$cfgpfx.mainrepo=$mainrepo
+EOF
+my $config = PublicInbox::Config->new(\$cfg);
my $www = PublicInbox::WWW->new($config);
test_psgi(sub { $www->call(@_) }, sub {
my ($cb) = @_;
my $www = PublicInbox::WWW->new($config);
test_psgi(sub { $www->call(@_) }, sub {
my ($cb) = @_;
use PublicInbox::WWW;
use Plack::Builder;
use Plack::App::URLMap;
use PublicInbox::WWW;
use Plack::Builder;
use Plack::App::URLMap;
-my $config = PublicInbox::Config->new({
- "$cfgpfx.address" => $addr,
- "$cfgpfx.mainrepo" => $maindir,
-});
+my $config = PublicInbox::Config->new(\<<EOF);
+$cfgpfx.address=$addr
+$cfgpfx.mainrepo=$maindir
+EOF
is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
my $git = PublicInbox::Git->new($maindir);
my $im = PublicInbox::Import->new($git, 'test', $addr);
is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
my $git = PublicInbox::Git->new($maindir);
my $im = PublicInbox::Import->new($git, 'test', $addr);
$im->done;
my $cfgpfx = "publicinbox.v2test";
$im->done;
my $cfgpfx = "publicinbox.v2test";
-my $cfg = {
- "$cfgpfx.address" => $ibx->{-primary_address},
- "$cfgpfx.mainrepo" => $repo,
-};
-my $config = PublicInbox::Config->new($cfg);
+my $cfg = <<EOF;
+$cfgpfx.address=$ibx->{-primary_address}
+$cfgpfx.mainrepo=$repo
+EOF
+my $config = PublicInbox::Config->new(\$cfg);
my $www = PublicInbox::WWW->new($config);
my ($res, $raw);
my $www = PublicInbox::WWW->new($config);
my ($res, $raw);
use_ok 'PublicInbox::V2Writable';
foreach my $mod (@mods) { use_ok $mod; }
my $tmp = tempdir('pi-scan_all-XXXXXX', TMPDIR => 1, CLEANUP => 1);
use_ok 'PublicInbox::V2Writable';
foreach my $mod (@mods) { use_ok $mod; }
my $tmp = tempdir('pi-scan_all-XXXXXX', TMPDIR => 1, CLEANUP => 1);
foreach my $i (1..2) {
my $cfgpfx = "publicinbox.test-$i";
foreach my $i (1..2) {
my $cfgpfx = "publicinbox.test-$i";
- my $addr = $cfg->{"$cfgpfx.address"} = "test-$i\@example.com";
- my $mainrepo = $cfg->{"$cfgpfx.mainrepo"} = "$tmp/$i";
- $cfg->{"$cfgpfx.url"} = "http://example.com/$i";
+ my $addr = "test-$i\@example.com";
+ my $mainrepo = "$tmp/$i";
+ $cfg .= "$cfgpfx.address=$addr\n";
+ $cfg .= "$cfgpfx.mainrepo=$mainrepo\n";
+ $cfg .= "$cfgpfx.url=http://example.com/$i\n";
my $opt = {
mainrepo => $mainrepo,
name => "test-$i",
my $opt = {
mainrepo => $mainrepo,
name => "test-$i",
ok($im->add($mime), "added message to $i");
$im->done;
}
ok($im->add($mime), "added message to $i");
$im->done;
}
-my $config = PublicInbox::Config->new($cfg);
+my $config = PublicInbox::Config->new(\$cfg);
use_ok 'PublicInbox::WWW';
my $www = PublicInbox::WWW->new($config);
use_ok 'PublicInbox::WWW';
my $www = PublicInbox::WWW->new($config);
PublicInbox::SearchIdx->new($ibx, 1)->index_sync;
my $cfgpfx = "publicinbox.test";
PublicInbox::SearchIdx->new($ibx, 1)->index_sync;
my $cfgpfx = "publicinbox.test";
-my $config = PublicInbox::Config->new({
- "$cfgpfx.address" => 'git@vger.kernel.org',
- "$cfgpfx.mainrepo" => $tmpdir,
-});
+my $config = PublicInbox::Config->new(\<<EOF);
+$cfgpfx.address=git\@vger.kernel.org
+$cfgpfx.mainrepo=$tmpdir
+EOF
my $www = PublicInbox::WWW->new($config);
test_psgi(sub { $www->call(@_) }, sub {
my ($cb) = @_;
my $www = PublicInbox::WWW->new($config);
test_psgi(sub { $www->call(@_) }, sub {
my ($cb) = @_;
use PublicInbox::WWW;
use_ok 'PublicInbox::WwwText';
use Plack::Builder;
use PublicInbox::WWW;
use_ok 'PublicInbox::WwwText';
use Plack::Builder;
-my $config = PublicInbox::Config->new({
- "$cfgpfx.address" => $addr,
- "$cfgpfx.mainrepo" => $maindir,
-});
+my $config = PublicInbox::Config->new(\<<EOF);
+$cfgpfx.address=$addr
+$cfgpfx.mainrepo=$maindir
+EOF
is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
my $www = PublicInbox::WWW->new($config);
is(0, system(qw(git init -q --bare), $maindir), "git init (main)");
my $www = PublicInbox::WWW->new($config);
$im->done;
my $cfgpfx = "publicinbox.v2test";
$im->done;
my $cfgpfx = "publicinbox.v2test";
-my $cfg = {
- "$cfgpfx.address" => $ibx->{-primary_address},
- "$cfgpfx.mainrepo" => $mainrepo,
-};
-my $config = PublicInbox::Config->new($cfg);
+my $cfg = <<EOF;
+$cfgpfx.address=$ibx->{-primary_address}
+$cfgpfx.mainrepo=$mainrepo
+EOF
+my $config = PublicInbox::Config->new(\$cfg);
my $www = PublicInbox::WWW->new($config);
my ($res, $raw, @from_);
test_psgi(sub { $www->call(@_) }, sub {
my $www = PublicInbox::WWW->new($config);
my ($res, $raw, @from_);
test_psgi(sub { $www->call(@_) }, sub {
EOF
PublicInbox::Emergency->new($maildir)->prepare(\"$spam");
EOF
PublicInbox::Emergency->new($maildir)->prepare(\"$spam");
- my %orig = (
- "$cfgpfx.address" => $addr,
- "$cfgpfx.mainrepo" => $mainrepo,
- "$cfgpfx.watch" => "maildir:$maildir",
- "$cfgpfx.filter" => 'PublicInbox::Filter::RubyLang',
- "$cfgpfx.altid" => 'serial:alerts:file=msgmap.sqlite3',
- "publicinboxwatch.watchspam" => "maildir:$spamdir",
- );
- my $config = PublicInbox::Config->new({%orig});
+ my $orig = <<EOF;
+$cfgpfx.address=$addr
+$cfgpfx.mainrepo=$mainrepo
+$cfgpfx.watch=maildir:$maildir
+$cfgpfx.filter=PublicInbox::Filter::RubyLang
+$cfgpfx.altid=serial:alerts:file=msgmap.sqlite3
+publicinboxwatch.watchspam=maildir:$spamdir
+EOF
+ my $config = PublicInbox::Config->new(\$orig);
my $ibx = $config->lookup_name($v);
ok($ibx, 'found inbox by name');
my $ibx = $config->lookup_name($v);
ok($ibx, 'found inbox by name');
- $config = PublicInbox::Config->new({%orig});
+ $config = PublicInbox::Config->new(\$orig);
$ibx = $config->lookup_name($v);
($tot, undef) = $ibx->search->reopen->query('b:spam');
is($tot, 0, 'spam removed');
$ibx = $config->lookup_name($v);
($tot, undef) = $ibx->search->reopen->query('b:spam');
is($tot, 0, 'spam removed');
'create FIFO to ensure we do not get stuck on it :P');
my $sem = PublicInbox::Emergency->new($spamdir); # create dirs
'create FIFO to ensure we do not get stuck on it :P');
my $sem = PublicInbox::Emergency->new($spamdir); # create dirs
-my $config = PublicInbox::Config->new({
- "$cfgpfx.address" => $addr,
- "$cfgpfx.mainrepo" => $git_dir,
- "$cfgpfx.watch" => "maildir:$maildir",
- "$cfgpfx.filter" => 'PublicInbox::Filter::Vger',
- "publicinboxlearn.watchspam" => "maildir:$spamdir",
-});
+my $config = PublicInbox::Config->new(\<<EOF);
+$cfgpfx.address=$addr
+$cfgpfx.mainrepo=$git_dir
+$cfgpfx.watch=maildir:$maildir
+$cfgpfx.filter=PublicInbox::Filter::Vger
+publicinboxlearn.watchspam=maildir:$spamdir
+EOF
PublicInbox::WatchMaildir->new($config)->scan('full');
my $git = PublicInbox::Git->new($git_dir);
PublicInbox::WatchMaildir->new($config)->scan('full');
my $git = PublicInbox::Git->new($git_dir);
'create FIFO to ensure we do not get stuck on it :P');
my $sem = PublicInbox::Emergency->new($spamdir); # create dirs
'create FIFO to ensure we do not get stuck on it :P');
my $sem = PublicInbox::Emergency->new($spamdir); # create dirs
-my %orig = (
- "$cfgpfx.address" => $addr,
- "$cfgpfx.mainrepo" => $mainrepo,
- "$cfgpfx.watch" => "maildir:$maildir",
- "$cfgpfx.filter" => 'PublicInbox::Filter::Vger',
- "publicinboxlearn.watchspam" => "maildir:$spamdir"
-);
-my $config = PublicInbox::Config->new({%orig});
+my $orig = <<EOF;
+$cfgpfx.address=$addr
+$cfgpfx.mainrepo=$mainrepo
+$cfgpfx.watch=maildir:$maildir
+$cfgpfx.filter=PublicInbox::Filter::Vger
+publicinboxlearn.watchspam=maildir:$spamdir
+EOF
+my $config = PublicInbox::Config->new(\$orig);
my $ibx = $config->lookup_name('test');
ok($ibx, 'found inbox by name');
my $srch = $ibx->search;
my $ibx = $config->lookup_name('test');
ok($ibx, 'found inbox by name');
my $srch = $ibx->search;
my $v1pfx = "publicinbox.v1";
my $v1addr = 'v1-public@example.com';
is(system(qw(git init -q --bare), $v1repo), 0, 'v1 init OK');
my $v1pfx = "publicinbox.v1";
my $v1addr = 'v1-public@example.com';
is(system(qw(git init -q --bare), $v1repo), 0, 'v1 init OK');
- my $config = PublicInbox::Config->new({
- %orig,
- "$v1pfx.address" => $v1addr,
- "$v1pfx.mainrepo" => $v1repo,
- "$v1pfx.watch" => "maildir:$maildir",
- });
+ my $cfg2 = <<EOF;
+$orig$v1pfx.address=$v1addr
+$v1pfx.mainrepo=$v1repo
+$v1pfx.watch=maildir:$maildir
+EOF
+ my $config = PublicInbox::Config->new(\$cfg2);
my $both = <<EOF;
From: user\@example.com
To: $addr, $v1addr
my $both = <<EOF;
From: user\@example.com
To: $addr, $v1addr