Blame installcheck/amcheckdump.pl

Packit Service 392537
# Copyright (c) 2007-2012 Zmanda, Inc.  All Rights Reserved.
Packit Service 392537
# Copyright (c) 2013-2016 Carbonite, Inc.  All Rights Reserved.
Packit Service 392537
#
Packit Service 392537
# This program is free software; you can redistribute it and/or
Packit Service 392537
# modify it under the terms of the GNU General Public License
Packit Service 392537
# as published by the Free Software Foundation; either version 2
Packit Service 392537
# of the License, or (at your option) any later version.
Packit Service 392537
#
Packit Service 392537
# This program is distributed in the hope that it will be useful, but
Packit Service 392537
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
Packit Service 392537
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
Packit Service 392537
# for more details.
Packit Service 392537
#
Packit Service 392537
# You should have received a copy of the GNU General Public License along
Packit Service 392537
# with this program; if not, write to the Free Software Foundation, Inc.,
Packit Service 392537
# 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
Packit Service 392537
#
Packit Service 392537
# Contact information: Carbonite Inc., 756 N Pastoria Ave
Packit Service 392537
# Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
Packit Service 392537
Packit Service 392537
use Test::More tests => 8;
Packit Service 392537
use strict;
Packit Service 392537
use warnings;
Packit Service 392537
Packit Service 392537
use lib '@amperldir@';
Packit Service 392537
use Installcheck::Config;
Packit Service 392537
use Installcheck::Dumpcache;
Packit Service 392537
use Installcheck::Run qw(run run_get run_err $diskname);
Packit Service 392537
use Amanda::Paths;
Packit Service 392537
Packit Service 392537
# set up debugging so debug output doesn't interfere with test results
Packit Service 392537
Amanda::Debug::dbopen("installcheck");
Packit Service 392537
Installcheck::log_test_output();
Packit Service 392537
Packit Service 392537
# and disable Debug's die() and warn() overrides
Packit Service 392537
Amanda::Debug::disable_die_override();
Packit Service 392537
Packit Service 392537
Packit Service 392537
my $testconf;
Packit Service 392537
Packit Service 392537
##
Packit Service 392537
# First, try amgetconf out without a config
Packit Service 392537
Packit Service 392537
ok(!run('amcheckdump'),
Packit Service 392537
    "amcheckdump with no arguments returns an error exit status");
Packit Service 392537
like($Installcheck::Run::stdout, qr/\AUSAGE:/i, 
Packit Service 392537
    ".. and gives usage message");
Packit Service 392537
Packit Service 392537
like(run_err('amcheckdump', 'this-probably-doesnt-exist'), qr(could not open conf file)i, 
Packit Service 392537
    "run with non-existent config fails with an appropriate error message.");
Packit Service 392537
Packit Service 392537
##
Packit Service 392537
# Now use a config with a vtape and without usetimestamps
Packit Service 392537
Packit Service 392537
$testconf = Installcheck::Run::setup();
Packit Service 392537
$testconf->write();
Packit Service 392537
Packit Service 392537
ok(!run('amcheckdump', 'TESTCONF'),
Packit Service 392537
    "amcheckdump with a new config succeeds");
Packit Service 392537
like($Installcheck::Run::stdout, qr(No matching dumps found)i,
Packit Service 392537
     "..but finds no dumps.");
Packit Service 392537
Packit Service 392537
##
Packit Service 392537
# and check command-line handling
Packit Service 392537
Packit Service 392537
Installcheck::Dumpcache::load("basic");
Packit Service 392537
Packit Service 392537
like(run_get('amcheckdump', 'TESTCONF', '-oorg=installcheck'), qr(Validating),
Packit Service 392537
    "amcheckdump accepts '-o' options on the command line");
Packit Service 392537
Packit Service 392537
##
Packit Service 392537
# Try with usetimestamps enabled
Packit Service 392537
Packit Service 392537
like(run_get('amcheckdump', 'TESTCONF'), qr(Validating),
Packit Service 392537
    "amcheckdump succeeds, claims to validate something (usetimestamps=yes)");
Packit Service 392537
Packit Service 392537
##
Packit Service 392537
# now try zeroing out the dumps
Packit Service 392537
Packit Service 392537
my $vtape1 = Installcheck::Run::vtape_dir(1);
Packit Service 392537
opendir(my $vtape_dir, $vtape1) || die "can't opendir $vtape1: $!";
Packit Service 392537
my @dump1 = grep { /^0+1/ } readdir($vtape_dir);
Packit Service 392537
closedir $vtape_dir;
Packit Service 392537
Packit Service 392537
for my $dumpfile (@dump1) {
Packit Service 392537
    open(my $dumpfh, "+<", "$vtape1/$dumpfile");
Packit Service 392537
    sysseek($dumpfh, 32768, 0); # jump past the header
Packit Service 392537
    syswrite($dumpfh, "\0" x 100); # and write some zeroes
Packit Service 392537
    close($dumpfh);
Packit Service 392537
}
Packit Service 392537
Packit Service 392537
ok(!run('amcheckdump', 'TESTCONF'),
Packit Service 392537
    "amcheckdump detects a failure from a zeroed-out dumpfile");
Packit Service 392537
Packit Service 392537
Installcheck::Run::cleanup();