source: trunk/t/DNSTest.pm@ 945

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

/trunk/t

Tweak test calls checking the DB
See #88

  • Property svn:keywords set to Date Rev Author Id
File size: 2.2 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 945 2025-12-24 17:35:14Z 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 DNSDB::DNSTest;
24use strict;
25use warnings;
26
27use Test::More;
28
29use lib '.';
30use DNSDB;
31
32our $dnsdb;
33our $dbh;
34
35sub new {
36 $dnsdb = new DNSDB(
37 dbhost => 'localhost',
38 dbname => 'dnstest',
39 dbuser => 'dnstest',
40 dbpass => 'dnstestpwd',
41 );
42 ok( defined $dnsdb );
43 ok( $dnsdb->isa('DNSDB') );
44
45 ## Prepare the DB
46 # 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 $dbh = $dnsdb->{dbh};
50
51 my ($dcount) = $dbh->selectrow_array("SELECT count(*) FROM domains");
52 BAIL_OUT("# DB looks like it may not be a test DB, found $dcount > 10 domains!\n")
53 if $dcount > 10;
54 ok( $dcount, '<=', 10, "domain count ($dcount): looks like a test DB" );
55
56 my ($rcount) = $dbh->selectrow_array("SELECT count(*) FROM records");
57 BAIL_OUT("# DB looks like it may not be a test DB, found $rcount > 30 records!\n")
58 if $rcount > 50;
59 ok( $rcount, '<=', 50, "record ($rcount): looks like a test DB" );
60
61 # drop all tables etc
62 $ENV{PGPASSWORD} = $dnsdb->{dbpass};
63 diag qx( psql -h $dnsdb->{dbhost} -U $dnsdb->{dbuser} $dnsdb->{dbname} < t/dropall.sql );
64 # load some standard test data
65 diag qx( psql -h $dnsdb->{dbhost} -U $dnsdb->{dbuser} $dnsdb->{dbname} < t/dns-unitbase.sql );
66
67}
68
69sub DESTROY {
70 $dnsdb->finish;
71}
72
731;
Note: See TracBrowser for help on using the repository browser.