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