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