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