1# Copyright (c) 2007-2013 Zmanda, Inc.  All Rights Reserved.
2#
3# This program is free software; you can redistribute it and/or
4# modify it under the terms of the GNU General Public License
5# as published by the Free Software Foundation; either version 2
6# of the License, or (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful, but
9# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11# for more details.
12#
13# You should have received a copy of the GNU General Public License along
14# with this program; if not, write to the Free Software Foundation, Inc.,
15# 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16#
17# Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
18# Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
19
20use Test::More tests => 9;
21use strict;
22use warnings;
23
24use lib "@amperldir@";
25use Installcheck::Config;
26use Installcheck::Dumpcache;
27use Installcheck::Run qw(run run_get run_err $diskname);
28use Amanda::Paths;
29
30my $testconf;
31
32##
33# First, try amgetconf out without a config
34
35ok(!run('amcheckdump'),
36    "amcheckdump with no arguments returns an error exit status");
37like($Installcheck::Run::stdout, qr/\AUSAGE:/i,
38    ".. and gives usage message");
39
40like(run_err('amcheckdump', 'this-probably-doesnt-exist'), qr(could not open conf file)i,
41    "run with non-existent config fails with an appropriate error message.");
42
43##
44# Now use a config with a vtape and without usetimestamps
45
46$testconf = Installcheck::Run::setup();
47$testconf->write();
48
49ok(run('amcheckdump', 'TESTCONF'),
50    "amcheckdump with a new config succeeds");
51like($Installcheck::Run::stdout, qr(could not find)i,
52     "..but finds no dumps.");
53
54Installcheck::Dumpcache::load("notimestamps");
55
56like(run_get('amcheckdump', 'TESTCONF'), qr(Validating),
57    "amcheckdump succeeds, claims to validate something (usetimestamps=no)");
58
59##
60# and check command-line handling
61
62like(run_get('amcheckdump', 'TESTCONF', '-oorg=installcheck'), qr(Validating),
63    "amcheckdump accepts '-o' options on the command line");
64
65##
66# Try with usetimestamps enabled
67
68Installcheck::Dumpcache::load("basic");
69
70like(run_get('amcheckdump', 'TESTCONF'), qr(Validating),
71    "amcheckdump succeeds, claims to validate something (usetimestamps=yes)");
72
73##
74# now try zeroing out the dumps
75
76my $vtape1 = Installcheck::Run::vtape_dir(1);
77opendir(my $vtape_dir, $vtape1) || die "can't opendir $vtape1: $!";
78my @dump1 = grep { /^0+1/ } readdir($vtape_dir);
79closedir $vtape_dir;
80
81for my $dumpfile (@dump1) {
82    open(my $dumpfh, "+<", "$vtape1/$dumpfile");
83    sysseek($dumpfh, 32768, 0); # jump past the header
84    syswrite($dumpfh, "\0" x 100); # and write some zeroes
85    close($dumpfh);
86}
87
88ok(!run('amcheckdump', 'TESTCONF'),
89    "amcheckdump detects a failure from a zeroed-out dumpfile");
90
91Installcheck::Run::cleanup();
92