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