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