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