Imported Upstream version 2.6.0
[debian/amanda] / installcheck / amdevcheck.pl
1 # Copyright (c) 2006 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, 505 N Mathlida Ave, Suite 120
17 # Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
18
19 use Test::More qw( no_plan );
20
21 use Amconfig;
22 use lib "@amperldir@";
23 use Amanda::Paths;
24
25 sub amdevcheck {
26     my $cmd = "$sbindir/amdevcheck " . join(" ", @_) . " 2>&1";
27     my $result = `$cmd`;
28     chomp $result;
29     return $result;
30 }
31
32 my $testconf;
33
34 ##
35 # First, try amgetconf out without a config
36
37 like(amdevcheck(), qr(\AUsage: )i, 
38     "bare 'amdevcheck' gives usage message");
39 like(amdevcheck("this-probably-doesnt-exist"), qr(could not open conf file)i, 
40     "error message when configuration parameter doesn't exist");
41
42 ##
43 # Next, work against a basically empty config
44
45 # this is re-created for each test
46 $testconf = Amconfig->new();
47 $testconf->add_param("tapedev", '"/dev/null"');
48 $testconf->write();
49
50 # test some defaults
51 like(amdevcheck('TESTCONF'), qr{File /dev/null is not a tape device},
52     "uses tapedev by default");
53
54 ##
55 # Now use a config with a vtape
56
57 # this is re-created for each test
58 $testconf = Amconfig->new();
59 $testconf->setup_vtape();
60 $testconf->write();
61
62 is_deeply([ sort split "\n", amdevcheck('TESTCONF') ],
63           [ sort "VOLUME_UNLABELED", "VOLUME_ERROR", "DEVICE_ERROR" ],
64     "empty vtape described as VOLUME_UNLABELED, VOLUME_ERROR, DEVICE_ERROR");
65
66 like(amdevcheck('TESTCONF', "/dev/null"), qr{File /dev/null is not a tape device},
67     "can override device on the command line");