--- a/lib/DNS/Vi.pm Wed Jan 14 09:18:35 2015 +0100
+++ b/lib/DNS/Vi.pm Wed Jan 21 20:33:49 2015 +0100
@@ -17,17 +17,22 @@
# the sort order for the records of the same label
my %ORDER = map { state $n = 0; $_ => ++$n } qw(SOA NS TXT MX A AAAA SSHFP);
+# input $arg - hash with options
+# $data - a long string with the zone data
sub parse {
my %arg = %{ pop @_ } if ref $_[-1] eq 'HASH';
my $data = shift;
my @lines = split /\n/, $data;
+ ### @lines
+
my @zone;
my ($origin, $ttl, $last_label, $soa_seen);
foreach (@lines) {
- s{;.*$}{};
- given ($_) {
+ s{;.*$}{}; # strip trailing comments
+ s{\s*$}{}; # strip off trailing spaces
+ for ($_) {
when (m{^\s*$}) { next }
when (m{^\s*\$ORIGIN\s+(\S+)}) { $origin = $1 }
when (m{^\s*\$TTL\s+(\S+)}) { $ttl = $1 }
--- a/t/10-dnsvi.t Wed Jan 14 09:18:35 2015 +0100
+++ b/t/10-dnsvi.t Wed Jan 21 20:33:49 2015 +0100
@@ -40,13 +40,19 @@
MX => 0,
},
b => {
- RRSETS => 7,
+ RRSETS => 11,
SOA => 1,
NS => 2,
A => 1,
TXT => 3,
AAAA => 0,
MX => 0,
+ CNAME => {
+ 'foo.km21.de.' => [qw/tte.km21.de./],
+ 'bar.km21.de.' => [qw/tte.km21.de./],
+ 'baz.km21.de.' => [qw/tte.km21.de./],
+ 'faz.km21.de.' => [qw/a.b.c./],
+ },
},
c => {
RRSETS => 12,
@@ -81,25 +87,33 @@
grep { $_ ne 'RRSETS' } sort keys %h;
};
-#foreach my $sample (sort keys %expect) {
-foreach my $sample ('d') {
+foreach my $sample (sort keys %expect) {
my $file = "t/samples/$sample";
subtest "sample $file" => sub {
my %expect = %{ $expect{$sample} };
my @zone = parse(slurp $file);
-# use Data::Dumper;
# diag Dumper \@zone;
is @zone, $expect{RRSETS} => "$sample: $expect{RRSETS} RRSETS";
foreach my $type (@sets) {
# diag '----------->' . $type;
- if (ref $expect{$type}) {
+ if (ref $expect{$type} eq ref[]) {
my @entries = sort map { $_->{label} } grep { $_->{rrtype} eq $type } map { $_->{rrset} } @zone;
is_deeply \@entries, $expect{$type} => 'list of labels';
}
+ elsif (ref $expect{$type} eq ref{}) {
+# use Data::Dumper;
+ foreach my $label (keys %{ $expect{$type} }) {
+ #diag Dumper $expect{$type}{$label};
+ #diag Dumper $expect{$type};
+ my @entries = sort map { $_->{data} } grep { $_->{label} eq $label and $_->{rrtype} eq $type } map { $_->{rrset} } @zone;
+# diag Dumper \@entries;
+ is_deeply \@entries, $expect{$type}{$label} => 'complete rrsets',
+ }
+ }
else {
is grep({ $_->{rrset}{rrtype} eq $type } @zone),
- $expect{$type} => "number of $type rrsets\n";
+ $expect{$type}//0 => "number of $type rrsets\n";
}
}
--- a/t/samples/b Wed Jan 14 09:18:35 2015 +0100
+++ b/t/samples/b Wed Jan 21 20:33:49 2015 +0100
@@ -8,3 +8,8 @@
TXT "utf8: km21.de"
TXT "start: 1396981300 2014-04-08T20:21:40"
tte A 85.214.245.1
+foo CNAME tte
+bar CNAME tte ;
+; do not remove the trailing spaces from the next line!
+baz CNAME tte
+faz CNAME a.b.c. ;