Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

xsawyerx (8978)

  (email not shown publicly)

Journal of xsawyerx (8978)

Tuesday January 12, 2010
03:44 AM

Hello Clarity

[ #40092 ]

this was originally posted on my new journal, which can be found here.

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.


The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.