Configd
view release on metacpan or search on metacpan
t/Configd-Language-postfix.t view on Meta::CPAN
#!/usr/bin/env perl
use 5.034;
use strict;
use warnings FATAL => 'all';
use re '/aa';
=head1 NAME
t/Configd-Language-postfix.t - reading main.cf and master.cf, and what happens
when two fragments have something to say about the same parameter
=cut
use Test::More;
use Test::Fatal qw{exception};
use FindBin::libs;
use Configd::Language::postfix(); ## no critic (ProhibitUnusedImports)
my $postfix = 'Configd::Language::postfix'->new();
sub value_of {
my ( $directives, $key ) = @_;
my ($found) = grep { defined $_->{key} && $_->{key} eq $key } @$directives;
return $found ? $found->{value} : undef;
}
subtest 'main.cf is parameters, comments and continuations' => sub {
my $parsed = $postfix->parse(<<'CF');
# A comment
myhostname = mail.example.com
mydestination = example.com, localhost
smtpd_recipient_restrictions =
permit_mynetworks
reject_unauth_destination
CF
is( value_of( $parsed, 'myhostname' ), 'mail.example.com', 'a parameter' );
# Postfix continues a value onto any following line that starts with
# whitespace. Treating those as parameters of their own would lose them.
is(
value_of( $parsed, 'smtpd_recipient_restrictions' ),
'permit_mynetworks reject_unauth_destination',
'a value continued over two lines is one value'
);
my @comments = grep { !defined $_->{key} } @$parsed;
ok( scalar @comments, 'comments and blank lines survive parsing' );
};
subtest 'a parameter said twice is the later one' => sub {
my $merged = $postfix->merge(
$postfix->parse("myhostname = first.example.com\n"),
$postfix->parse("myhostname = second.example.com\n"),
);
is( value_of( $merged, 'myhostname' ), 'second.example.com', 'the later fragment wins' );
};
subtest 'two domains on one mail server both stay local' => sub {
# The case the whole distribution exists for. postconf -e sets
# mydestination, so provisioning the second domain onto a server that
# already hosts the first replaces it -- and mail for the first domain
# quietly stops being delivered locally.
my $merged = $postfix->merge(
$postfix->parse("mydestination = \$myhostname, localhost\n"),
$postfix->parse("mydestination = first.example.com\nvirtual_mailbox_domains = first.example.com\n"),
$postfix->parse("mydestination = second.example.com\nvirtual_mailbox_domains = second.example.com\n"),
);
my $destination = value_of( $merged, 'mydestination' );
( run in 1.029 second using v1.01-cache-2.11-cpan-54e63673c56 )