source: trunk/t/DNSTest.pm@ 943

Last change on this file since 943 was 943, checked in by Kris Deugau, 17 hours ago

/trunk

Finally start building out a test suite rather than relying on hand-testing.
See #88

File size: 1.9 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$
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 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
59 $dbh = $dnsdb->{dbh};
60}
61
62sub DESTROY {
63 $dnsdb->finish;
64}
65
661;
Note: See TracBrowser for help on using the repository browser.