source: branches/cname-collision/t/DNSTest.pm@ 978

Last change on this file since 978 was 977, checked in by Kris Deugau, 7 days ago

/branches/cname-collision

Fix misplaced handpatch from previous.

  • Property svn:keywords set to Date Rev Author Id
File size: 2.8 KB
RevLine 
[943]1# -*- Perl -*-
2
3# Base class for DNSDB.pm unit testing
4# Sets up DB connection and repopulates it for a consistent test reference
5##
6# $Id: DNSTest.pm 977 2026-01-09 18:02:36Z kdeugau $
7# Copyright 2025 Kris Deugau <kdeugau@deepnet.cx>
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
21##
22
[946]23package DNSTest;
[943]24use strict;
25use warnings;
[946]26use Exporter;
27use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
28@ISA = qw(Exporter);
29@EXPORT = qw($dnsdb $dbh);
[943]30
31use Test::More;
32
33use lib '.';
34use DNSDB;
35
36our $dnsdb;
37our $dbh;
[949]38our $debug;
[943]39
40sub new {
[962]41 my $this = shift;
42 my $class = ref($this) || $this;
43 my %args = @_;
44
[943]45 $dnsdb = new DNSDB(
46 dbhost => 'localhost',
47 dbname => 'dnstest',
48 dbuser => 'dnstest',
49 dbpass => 'dnstestpwd',
50 );
51 ok( defined $dnsdb );
52 ok( $dnsdb->isa('DNSDB') );
53
[962]54 $debug = 1 if $args{debug};
55
[943]56 ## Prepare the DB
57 # Check that we aren't in an obviously production DB before blowing it away.
58 # A DB instantiated for these tests should NEVER have more than a handful of domains and maybe 20-30 records.
59
[945]60 $dbh = $dnsdb->{dbh};
61
[943]62 my ($dcount) = $dbh->selectrow_array("SELECT count(*) FROM domains");
63 BAIL_OUT("# DB looks like it may not be a test DB, found $dcount > 10 domains!\n")
64 if $dcount > 10;
[949]65 cmp_ok( $dcount, '<=', 10, "domain count ($dcount): looks like a test DB" );
[943]66
67 my ($rcount) = $dbh->selectrow_array("SELECT count(*) FROM records");
[972]68 my $maxrecs = 60;
69 BAIL_OUT("# DB looks like it may not be a test DB, found $rcount > $maxrecs records!\n")
70 if $rcount > $maxrecs;
71 cmp_ok( $rcount, '<=', $maxrecs, "record ($rcount): looks like a test DB" );
[943]72
[944]73 # drop all tables etc
74 $ENV{PGPASSWORD} = $dnsdb->{dbpass};
[949]75# neither diag or note seem to suppress output from qx
76 my $dropdata = qx( psql -h $dnsdb->{dbhost} -U $dnsdb->{dbuser} $dnsdb->{dbname} 2>&1 < t/dropall.sql );
77 diag( $dropdata ) if $debug;
[944]78 # load some standard test data
[949]79 my $reload = qx( psql -h $dnsdb->{dbhost} -U $dnsdb->{dbuser} $dnsdb->{dbname} 2>&1 < t/dns-unitbase.sql );
80 diag( $reload ) if $debug;
[976]81 # Set timestamps to a sliding window
82 my $stampwindow = qx( psql -h $dnsdb->{dbhost} -U $dnsdb->{dbuser} $dnsdb->{dbname} 2>&1 < t/test-cname-timestamps.sql );
83 diag( $stampwindow ) if $debug;
[977]84 undef $ENV{PGPASSWORD};
[949]85} # new()
[944]86
[943]87sub DESTROY {
88 $dnsdb->finish;
89}
90
911;
Note: See TracBrowser for help on using the repository browser.