source: trunk/t/DNSTest.pm@ 949

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

/trunk/t

Patch up some fixes misplaced in patch shuffling
See #88

  • Property svn:keywords set to Date Rev Author Id
File size: 2.5 KB
Line 
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 948 2025-12-24 18:01:43Z 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
23package DNSTest;
24use strict;
25use warnings;
26use Exporter;
27use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
28@ISA = qw(Exporter);
29@EXPORT = qw($dnsdb $dbh);
30
31use Test::More;
32
33use lib '.';
34use DNSDB;
35
36our $dnsdb;
37our $dbh;
38our $debug;
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
54 $dbh = $dnsdb->{dbh};
55
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;
59 cmp_ok( $dcount, '<=', 10, "domain count ($dcount): looks like a test DB" );
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")
63 if $rcount > 50;
64 cmp_ok( $rcount, '<=', 50, "record ($rcount): looks like a test DB" );
65
66 # drop all tables etc
67 $ENV{PGPASSWORD} = $dnsdb->{dbpass};
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;
71 # load some standard test data
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()
76
77sub DESTROY {
78 $dnsdb->finish;
79}
80
811;
Note: See TracBrowser for help on using the repository browser.