1 # Copyright (c) 2008, 2009, 2010 Zmanda, Inc. All Rights Reserved.
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.
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
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
16 # Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
17 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
19 use Test::More tests => 3;
21 use lib "@amperldir@";
23 use Installcheck::Config;
24 use Installcheck::Run qw(run run_get run_err $diskname);
25 use Installcheck::Dumpcache;
27 use File::Path qw(rmtree mkpath);
38 if (!$Installcheck::Run::have_expect) {
40 skip("Expect.pm not available",
41 Test::More->builder->expected_tests);
46 # amrecover can successfully set the host if its hostname is localhost
47 my $hostname = hostname;
48 my $set_host_succeed = 0;
49 $set_host_succeed=1 if ( ($hostname eq "localhost")
50 or ($hostname =~ /localhost\./));
52 my $debug = !exists $ENV{'HARNESS_ACTIVE'};
53 diag("logging amrecover conversations to stdout because Test::Harness not in use")
57 my $testdir = "$Installcheck::TMP/amfetchdump-installcheck/files";
63 for my $filename (<$testdir/*>) {
78 my ($exp, $continued);
79 my @commands = @{$params{'commands'}};
82 my @h_opt = ('-h', 'localhost') unless $set_host_succeed;
83 $exp = Installcheck::Run::run_expect('amrecover', 'TESTCONF',
84 @h_opt, '-s', 'localhost', '-t', 'localhost', '-o', 'auth=local');
85 $exp->log_stdout($debug);
89 [ qr{220.*ready\.}, mkcont "server-ready" ],
90 [ qr{200 Config set to TESTCONF\.}, mkcont "config-set" ],
91 [ qr{Use the sethost command}, mkcont "use-sethost" ],
92 [ qr{syntax error}, mkcont "syntax-err" ],
93 [ qr{Invalid command:}, mkcont "invalid-cmd" ],
94 [ qr{200 Dump host set}, mkcont "host-set" ],
95 [ qr{200 Disk set to}, mkcont "disk-set" ],
96 [ qr{Added file /1kilobyte}, mkcont "added-file" ],
97 [ qr{The following tapes are needed:}, mkcont "tapes-needed" ],
98 [ qr{Load tape \S+ now}, mkcont "load-tape" ],
99 [ qr{Restoring files into directory}, mkcont "restoring-into" ],
100 [ qr{All existing files.*can be deleted}, mkcont "can-delete" ],
101 [ qr{\./1kilobyte}, mkcont "restored-file" ],
102 [ qr{200 Good bye}, mkcont "bye" ],
104 [ qr{amrecover> }, sub {
105 my $cmd = shift @commands or die "out of commands!";
106 push @results, "> $cmd";
107 $exp->send("$cmd\n");
110 [ qr{Continue \[\?/Y/n/s/d\]\?}, sub {
111 die "multiple Continue requests" if $continued;
114 push @results, "> continue-Y";
118 [ qr{Continue \[\?/Y/n\]\?}, sub { # the "all files" question
119 push @results, "> deletall-Y";
127 ## plain vanilla amrecover run
129 Installcheck::Dumpcache::load("basic");
140 is_deeply([ @results ], [
141 'server-ready', 'config-set',
143 '> sethost localhost',
145 "> setdisk $diskname",
150 'tapes-needed', 'load-tape',
152 'restoring-into', 'can-delete',
158 "simple restore follows the correct steps")
159 or diag Dumper([@results]);
161 ok((-f "1kilobyte" and ! -z "1kilobyte"),
162 "..restored file appears in current directory");
168 "sethost localhost ", # <-- note extra space
173 is_deeply([ @results ], [
174 'server-ready', 'config-set',
176 '> sethost localhost ',
178 '> sethost localhost',
183 "check trailling space")
184 or die Dumper([@results]);
190 Installcheck::Run::cleanup();