Imported Upstream version 3.3.3
[debian/amanda] / installcheck / amcheckdump.pl
1 # Copyright (c) 2007-2012 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
20 use Test::More tests => 9;
21 use strict;
22 use warnings;
23
24 use lib "@amperldir@";
25 use Installcheck::Config;
26 use Installcheck::Dumpcache;
27 use Installcheck::Run qw(run run_get run_err $diskname);
28 use Amanda::Paths;
29
30 my $testconf;
31
32 ##
33 # First, try amgetconf out without a config
34
35 ok(!run('amcheckdump'),
36     "amcheckdump with no arguments returns an error exit status");
37 like($Installcheck::Run::stdout, qr/\AUSAGE:/i, 
38     ".. and gives usage message");
39
40 like(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
49 ok(run('amcheckdump', 'TESTCONF'),
50     "amcheckdump with a new config succeeds");
51 like($Installcheck::Run::stdout, qr(could not find)i,
52      "..but finds no dumps.");
53
54 Installcheck::Dumpcache::load("notimestamps");
55
56 like(run_get('amcheckdump', 'TESTCONF'), qr(Validating),
57     "amcheckdump succeeds, claims to validate something (usetimestamps=no)");
58
59 ##
60 # and check command-line handling
61
62 like(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
68 Installcheck::Dumpcache::load("basic");
69
70 like(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
76 my $vtape1 = Installcheck::Run::vtape_dir(1);
77 opendir(my $vtape_dir, $vtape1) || die "can't opendir $vtape1: $!";
78 my @dump1 = grep { /^0+1/ } readdir($vtape_dir);
79 closedir $vtape_dir;
80
81 for 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
88 ok(!run('amcheckdump', 'TESTCONF'),
89     "amcheckdump detects a failure from a zeroed-out dumpfile");
90
91 Installcheck::Run::cleanup();