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

Last change on this file since 950 was 949, checked in by Kris Deugau, 27 hours ago

/branches/cname-collision

Merge test framework fixes

  • Property svn:keywords set to Date Rev Author Id
File size: 2.5 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 949 2025-12-24 18:17:17Z 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 {
41 $dnsdb = new DNSDB(
42 dbhost => 'localhost',
43 dbname => 'dnstest',
44 dbuser => 'dnstest',
45 dbpass => 'dnstestpwd',
46 );
47 ok( defined $dnsdb );
48 ok( $dnsdb->isa('DNSDB') );
49
50 ## Prepare the DB
51 # Check that we aren't in an obviously production DB before blowing it away.
52 # A DB instantiated for these tests should NEVER have more than a handful of domains and maybe 20-30 records.
53
[945]54 $dbh = $dnsdb->{dbh};
55
[943]56 my ($dcount) = $dbh->selectrow_array("SELECT count(*) FROM domains");
57 BAIL_OUT("# DB looks like it may not be a test DB, found $dcount > 10 domains!\n")
58 if $dcount > 10;
[949]59 cmp_ok( $dcount, '<=', 10, "domain count ($dcount): looks like a test DB" );
[943]60
61 my ($rcount) = $dbh->selectrow_array("SELECT count(*) FROM records");
62 BAIL_OUT("# DB looks like it may not be a test DB, found $rcount > 30 records!\n")
[945]63 if $rcount > 50;
[949]64 cmp_ok( $rcount, '<=', 50, "record ($rcount): looks like a test DB" );
[943]65
[944]66 # drop all tables etc
67 $ENV{PGPASSWORD} = $dnsdb->{dbpass};
[949]68# neither diag or note seem to suppress output from qx
69 my $dropdata = qx( psql -h $dnsdb->{dbhost} -U $dnsdb->{dbuser} $dnsdb->{dbname} 2>&1 < t/dropall.sql );
70 diag( $dropdata ) if $debug;
[944]71 # load some standard test data
[949]72 my $reload = qx( psql -h $dnsdb->{dbhost} -U $dnsdb->{dbuser} $dnsdb->{dbname} 2>&1 < t/dns-unitbase.sql );
73 diag( $reload ) if $debug;
74 undef $ENV{PGPASSWORD};
75} # new()
[944]76
[943]77sub DESTROY {
78 $dnsdb->finish;
79}
80
811;
Note: See TracBrowser for help on using the repository browser.