15e3cad75fe3fde4355c27adb371d580cf5f6f8d
[debian/amanda] / installcheck / amarchiver.pl
1 # Copyright (c) 2005-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 Mathlida Ave, Suite 300
17 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
18
19 use Test::More tests => 18;
20
21 use lib "@amperldir@";
22 use Installcheck::Run qw( run run_get );
23 use Amanda::Paths;
24 use Amanda::Constants;
25 use File::Path qw( mkpath rmtree );
26
27 my $tmpdir = "$AMANDA_TMPDIR/amarchiver-installcheck";
28 my $archfile = "$tmpdir/test.amar";
29 my $data = "abcd" x 500;
30 my $fh;
31
32 rmtree($tmpdir);
33 mkpath($tmpdir);
34 chdir($tmpdir);
35
36 open($fh, ">", "test.tmp-1");
37 print $fh $data;
38 close($fh);
39
40 open($fh, ">", "test.tmp-2");
41 print $fh $data;
42 close($fh);
43
44 ok(run('amarchiver', '--version'),
45     "amarchiver --version OK");
46 like($Installcheck::Run::stdout,
47     qr{^amarchiver },
48     "..and output is reasonable");
49
50 # test creating archives
51
52 ok(run('amarchiver', '--create', "test.tmp-1"),
53     "archive creation without --file succeeds");
54 like($Installcheck::Run::stdout, qr{^AMANDA ARCHIVE FORMAT },
55     "..and produces something that looks like an archive");
56
57 unlink($archfile);
58 ok(run('amarchiver', '--create', '--file', $archfile,
59         "$sbindir/amarchiver", "$sbindir/amgetconf"),
60     "archive creation succeeds");
61 ok(-f $archfile, "..and target file exists");
62
63 unlink($archfile);
64 ok(run('amarchiver', '--create', '--verbose', '--file', $archfile,
65         "$sbindir/amarchiver", "$sbindir/amgetconf"),
66     "archive creation with --verbose succeeds");
67 like($Installcheck::Run::stdout,
68     qr{^\Q$sbindir\E/amarchiver\n\Q$sbindir\E/amgetconf$},
69     "..and output is correct");
70
71 ok(run('amarchiver', '--create', '--verbose', $archfile),
72     "archive creation with --verbose and without --file succeeds");
73 like($Installcheck::Run::stderr,
74     qr{$archfile},
75     "..and output goes to stderr");
76
77 unlink($archfile);
78 ok(run('amarchiver', '--create', '--verbose', '--verbose', '--file', $archfile,
79         "$sbindir/amarchiver", "$sbindir/amgetconf", "test.tmp-1"),
80     "archive creation with two --verbose args succeeds");
81 like($Installcheck::Run::stdout,
82     qr{^[[:digit:]]+ \Q$sbindir\E/amarchiver\n[[:digit:]]+ \Q$sbindir\E/amgetconf\n2000 test.tmp-1$},
83     "..and output is correct");
84
85 # test listing archives
86
87 run('amarchiver', '--create', '--file', $archfile, "test.tmp-1", "test.tmp-2")
88     or BAIL_OUT("could not create an archive to test listing/extracting");
89
90 ok(run('amarchiver', '--list', '--file', $archfile),
91     "archive listing succeeds");
92 is($Installcheck::Run::stdout, "test.tmp-1\ntest.tmp-2\n",
93     "..and output is correct");
94
95 # test extracting archives
96
97 unlink("test.tmp-1.16");
98 unlink("test.tmp-2.16");
99 ok(run('amarchiver', '--extract', '--file', $archfile),
100     "archive extraction succeeds");
101 ok((-f "test.tmp-1.16" && -f "test.tmp-2.16"), "..and the files reappear")
102     or diag(`find .`);
103
104 unlink("test.tmp-1.16");
105 unlink("test.tmp-2.16");
106 ok(run('amarchiver', '--extract', '--file', $archfile, "test.tmp-2"),
107     "archive extraction of only one file succeeds");
108 ok((! -f "test.tmp-1.16" && -f "test.tmp-2.16"), "..and the file reappears")
109     or diag(`find .`);
110
111 END {
112     chdir("$tmpdir/..");
113     rmtree($tmpdir);
114 }