For two weeks we've been working hard on defining a rather complex construct of DNS zone files, using multiple servers for multiple domains with cross referencing them and a lot of other complex-sounding terms.
We wrote DNS tests for the zones to make sure all the servers are configured correctly and the general DNS fetching provides correct information. This turned out to be quite difficult.
The original script is 130 lines. This is without taking into account even more testing we wanted. There was a lot of analyzing done which was rather repetitive and the overall code was ugly and not fun to read (to put it in mild terms). I decided to write a testing module for DNS zones - Test::DNS.
Using Test::DNS, we rewrote the script with a lot more options, which we wanted. The resulting script (with the addons) is 20 lines. It's clean and readable.
Here is how Test::DNS looks:
use Test::More tests => 5 * $num_of_domains; use Test::DNS; my $dns = Test::DNS->new(); foreach my $domain (@domains) { # assuming $domain is an object $dns->is_ptr( $domain->ns1 => $domain->ptr1 ); $dns->is_ptr( $domain->ns2 => $domain->ptr2 ); $dns->is_ns( $domain => [ map { "ns$_.$domain" } 1 .. 2 ] ); # assuming there's overloading here $dns->is_a( "ns1.$domain" => $domain->ns1 ); $dns->is_a( "ns2.$domain" => $domain->ns2 ); }
Test::DNS will be available soon on CPAN.
Enjoy!