Imported Upstream version 3.3.3
[debian/amanda] / installcheck / amcheck.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 => 12;
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('amcheck'),
36     "amcheck 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('amcheck', 'this-probably-doesnt-exist'),
41     qr(could not open conf file)i,
42     "run with non-existent config fails with an appropriate error message.");
43
44 ##
45 # Now use a fresh new config
46
47 $testconf = Installcheck::Run::setup();
48 $testconf->add_param("autolabel", "\"TESTCONF%%\" empty volume_error");
49 $testconf->add_dle("localhost $diskname installcheck-test");
50 $testconf->write();
51
52 like(run_get('amcheck', 'TESTCONF'),
53     qr/Amanda Tape Server Host Check/,
54     "amcheck with a new config succeeds");
55
56 like(run_get('amcheck', '-s', 'TESTCONF'),
57     qr/Amanda Tape Server Host Check/,
58     "amcheck -s works");
59
60 like(run_get('amcheck', '-l', 'TESTCONF'),
61     qr/Amanda Tape Server Host Check/,
62     "amcheck -l works");
63
64 like(run_get('amcheck', '-t', 'TESTCONF'),
65     qr/Amanda Tape Server Host Check/,
66     "amcheck -t works");
67
68 like(run_get('amcheck', '-c', 'TESTCONF'),
69     qr/Amanda Backup Client Hosts Check/,
70     "amcheck -c works");
71
72 like(run_get('amcheck', '-c', 'TESTCONF', 'localhost', "$diskname"),
73     qr/Amanda Backup Client Hosts Check/,
74     "amcheck -c works with a hostname and diskname");
75
76 ok(!run('amcheck', '-o', 'autolabel=', 'TESTCONF'),
77     "amcheck -o configoption works");
78
79 # do this after the other tests, above, since it writes to the tape
80 like(run_get('amcheck', '-sw', 'TESTCONF'),
81     qr/Volume 'TESTCONF01' is writeable/,
82     "amcheck -w works (with -s)");
83
84 Installcheck::Dumpcache::load("basic");
85 ok(run('amcheck', 'TESTCONF'),
86     "amcheck on a cached dump run works");
87
88 Installcheck::Run::cleanup();