Ignore:
Timestamp:
03/05/26 18:20:36 (17 hours ago)
Author:
Kris Deugau
Message:

/branches/stable

Merge baseline test suite changes

Location:
branches/stable
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/stable

  • branches/stable/t/DNSTest.pm

    • Property svn:keywords set to Date Rev Author Id
    r943 r1050  
    2121##
    2222
    23 package DNSDB::DNSTest;
     23package DNSTest;
    2424use strict;
    2525use warnings;
     26use Exporter;
     27use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
     28@ISA            = qw(Exporter);
     29@EXPORT         = qw($dnsdb $dbh);
    2630
    2731use Test::More;
     
    3236our $dnsdb;
    3337our $dbh;
     38our $debug;
    3439
    3540sub new {
     41  my $this = shift;
     42  my $class = ref($this) || $this;
     43  my %args = @_;
     44
    3645  $dnsdb = new DNSDB(
    3746        dbhost => 'localhost',
     
    4352  ok( $dnsdb->isa('DNSDB') );
    4453
     54  $debug = 1 if $args{debug};
     55
    4556  ## Prepare the DB
    4657  # Check that we aren't in an obviously production DB before blowing it away.
    47   # A DB instantiated for these tests should NEVER have more than a handful of domains and maybe 20-30 records.
    48 
    49   my ($dcount) = $dbh->selectrow_array("SELECT count(*) FROM domains");
    50   BAIL_OUT("# DB looks like it may not be a test DB, found $dcount > 10 domains!\n")
    51         if $dcount > 10;
    52   cmp_ok( $dcount, '<=', 10, "domain count: looks like a test DB" );
    53 
    54   my ($rcount) = $dbh->selectrow_array("SELECT count(*) FROM records");
    55   BAIL_OUT("# DB looks like it may not be a test DB, found $rcount > 30 records!\n")
    56         if $rcount > 30;
    57   cmp_ok( $rcount, '<=', 30, "record count: looks like a test DB" );
     58  # A DB instantiated for these tests should have a known set of domains and records.
    5859
    5960  $dbh = $dnsdb->{dbh};
    60 }
     61
     62  my ($dcount) = $dbh->selectrow_array("SELECT count(*) FROM domains WHERE NOT domain IN ".
     63        "('example.com','example.net','example.org','expiry1.test','expiry2.test')");
     64  BAIL_OUT("# DB looks like it may not be a test DB, found $dcount > 0 non-test domains!\n")
     65        if $dcount > 0;
     66  cmp_ok( $dcount, '==', 0, "non-test domain count ($dcount): looks like a test DB" );
     67
     68  my ($rcount) = $dbh->selectrow_array(qq{SELECT count(*) FROM records WHERE NOT (
     69        host like '%example.com' or host like '%example.net' or host like '%example.org' or
     70        host like '%expiry1.test' or host like '%expiry2.test' or inetlazy(val) << '192.168.2.0/27'
     71        )});
     72  my $maxrecs = 0;
     73  BAIL_OUT("# DB looks like it may not be a test DB, found $rcount > $maxrecs records!\n")
     74        if $rcount > $maxrecs;
     75  cmp_ok( $rcount, '<=', $maxrecs, "non-test record ($rcount): looks like a test DB" );
     76
     77  # drop all tables etc
     78  $ENV{PGPASSWORD} = $dnsdb->{dbpass};
     79# neither diag or note seem to suppress output from qx
     80  my $dropdata = qx( psql -h $dnsdb->{dbhost} -U $dnsdb->{dbuser} $dnsdb->{dbname} 2>&1 < t/dropall.sql );
     81  diag( $dropdata ) if $debug;
     82  # load some standard test data
     83  my $reload = qx( psql -h $dnsdb->{dbhost} -U $dnsdb->{dbuser} $dnsdb->{dbname} 2>&1 < t/dns-unitbase.sql );
     84  diag( $reload ) if $debug;
     85  undef $ENV{PGPASSWORD};
     86} # new()
    6187
    6288sub DESTROY {
Note: See TracChangeset for help on using the changeset viewer.