e4c28e7afc8134f7e005a900ef3734a1b8cc903b
[debian/amanda] / installcheck / amcheckdump.pl
1 # Copyright (c) 2007,2008 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
21 use lib "@amperldir@";
22 use Installcheck::Config;
23 use Installcheck::Dumpcache;
24 use Installcheck::Run qw(run run_get run_err $diskname);
25 use Amanda::Paths;
26
27 my $testconf;
28
29 ##
30 # First, try amgetconf out without a config
31
32 ok(!run('amcheckdump'),
33     "amcheckdump with no arguments returns an error exit status");
34 like($Installcheck::Run::stdout, qr/\AUSAGE:/i, 
35     ".. and gives usage message");
36
37 like(run_err('amcheckdump', 'this-probably-doesnt-exist'), qr(could not open conf file)i, 
38     "run with non-existent config fails with an appropriate error message.");
39
40 ##
41 # Now use a config with a vtape and without usetimestamps
42
43 $testconf = Installcheck::Run::setup();
44 $testconf->write();
45
46 ok(run('amcheckdump', 'TESTCONF'),
47     "amcheckdump with a new config succeeds");
48 like($Installcheck::Run::stdout, qr(could not find)i,
49      "..but finds no dumps.");
50
51 Installcheck::Dumpcache::load("notimestamps");
52
53 like(run_get('amcheckdump', 'TESTCONF'), qr(Validating),
54     "amcheckdump succeeds, claims to validate something (usetimestamps=no)");
55
56 ##
57 # and check command-line handling
58
59 like(run_get('amcheckdump', 'TESTCONF', '-oorg=installcheck'), qr(Validating),
60     "amcheckdump accepts '-o' options on the command line");
61
62 ##
63 # Try with usetimestamps enabled
64
65 Installcheck::Dumpcache::load("basic");
66
67 like(run_get('amcheckdump', 'TESTCONF'), qr(Validating),
68     "amcheckdump succeeds, claims to validate something (usetimestamps=yes)");
69
70 ##
71 # now try zeroing out the dumps
72
73 my $vtape1 = Installcheck::Run::vtape_dir(1);
74 opendir(my $vtape_dir, $vtape1) || die "can't opendir $vtape1: $!";
75 @dump1 = grep { /^0+1/ } readdir($vtape_dir);
76 closedir $vtape_dir;
77
78 for my $dumpfile (@dump1) {
79     open(my $dumpfh, "+<", "$vtape1/$dumpfile");
80     sysseek($dumpfh, 32768, 0); # jump past the header
81     syswrite($dumpfh, "\0" x 100); # and write some zeroes
82     close($dumpfh);
83 }
84
85 ok(!run('amcheckdump', 'TESTCONF'),
86     "amcheckdump detects a failure from a zeroed-out dumpfile");
87
88 Installcheck::Run::cleanup();