Imported Upstream version 3.3.3
[debian/amanda] / installcheck / amraw.pl
1 # Copyright (c) 2009-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 => 15;
21
22 use lib "@amperldir@";
23 use strict;
24 use warnings;
25 use Installcheck;
26 use Amanda::Constants;
27 use Amanda::Paths;
28 use Amanda::Tests;
29 use File::Path;
30 use Installcheck::Application;
31 use IO::File;
32
33 unless ($Amanda::Constants::GNUTAR and -x $Amanda::Constants::GNUTAR) {
34     SKIP: {
35         skip("GNU tar is not available", Test::More->builder->expected_tests);
36     }
37     exit 0;
38 }
39
40 my $app = Installcheck::Application->new('amraw');
41
42 my $support = $app->support();
43 is($support->{'INDEX-LINE'}, 'YES', "supports indexing");
44 is($support->{'MESSAGE-LINE'}, 'YES', "supports messages");
45
46 my $root_dir = "$Installcheck::TMP/installcheck-amraw";
47 my $back_file = "$root_dir/to_backup";
48 my $rest_dir = "$root_dir/restore";
49
50 File::Path::mkpath($root_dir);
51 File::Path::mkpath($rest_dir);
52 Amanda::Tests::write_random_file(0xabcde, 1024*256, $back_file);
53
54 my $selfcheck = $app->selfcheck('device' => $back_file, 'level' => 0, 'index' => 'line');
55 is($selfcheck->{'exit_status'}, 0, "error status ok");
56 ok(!@{$selfcheck->{'errors'}}, "no errors during selfcheck");
57
58 my $backup = $app->backup('device' => $back_file, 'level' => 0, 'index' => 'line');
59 is($backup->{'exit_status'}, 0, "error status ok");
60 ok(!@{$backup->{'errors'}}, "no errors during backup")
61     or diag(@{$backup->{'errors'}});
62
63 is(length($backup->{'data'}), $backup->{'size'}, "reported and actual size match");
64
65 ok(@{$backup->{'index'}}, "index is not empty");
66 is_deeply($backup->{'index'}, ["/"], "index is '/'");
67
68 my $orig_cur_dir = POSIX::getcwd();
69 ok($orig_cur_dir, "got current directory");
70
71 ok(chdir($rest_dir), "changed working directory (for restore)");
72
73 my $restore = $app->restore('objects' => ['.'],'data' => $backup->{'data'});
74 is($restore->{'exit_status'}, 0, "error status ok");
75
76 ok(chdir($orig_cur_dir), "changed working directory (back to original)");
77
78 my $restore_file = "$rest_dir/amraw-restored";
79 ok(-f "$restore_file", "amraw-restored restored");
80 is(`cmp $back_file $restore_file`, "", "restore match");
81
82 # cleanup
83 #exit(1);
84 rmtree($root_dir);