dad5e8a3aed6370495e8246ec7216e51cd8bc3d1
[debian/amanda] / installcheck / Amanda_Changer_null.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 => 4;
20 use File::Path;
21 use strict;
22
23 use lib "@amperldir@";
24 use Installcheck::Config;
25 use Installcheck::Changer;
26 use Amanda::Paths;
27 use Amanda::Device;
28 use Amanda::Debug;
29 use Amanda::MainLoop;
30 use Amanda::Config qw( :init :getconf config_dir_relative );
31 use Amanda::Changer;
32
33 # set up debugging so debug output doesn't interfere with test results
34 Amanda::Debug::dbopen("installcheck");
35 Installcheck::log_test_output();
36
37 # and disable Debug's die() and warn() overrides
38 Amanda::Debug::disable_die_override();
39
40 my $testconf = Installcheck::Config->new();
41 $testconf->write();
42
43 my $cfg_result = config_init($CONFIG_INIT_EXPLICIT_NAME, 'TESTCONF');
44 if ($cfg_result != $CFGERR_OK) {
45     my ($level, @errors) = Amanda::Config::config_errors();
46     die(join "\n", @errors);
47 }
48
49 my $chg = Amanda::Changer->new("chg-null:");
50 {
51     my ($get_info, $check_info, $do_load, $got_res);
52
53     $get_info = make_cb('get_info' => sub {
54         $chg->info(info_cb => $check_info, info => [ 'num_slots', 'fast_search' ]);
55     });
56
57     $check_info = make_cb('check_info' => sub {
58         my $err = shift;
59         my %results = @_;
60         die($err) if defined($err);
61
62         is_deeply({ %results },
63             { num_slots => 1, fast_search => 1 },
64             "info() returns the correct num_slots and fast_search");
65
66         $do_load->();
67     });
68
69     $do_load = make_cb('do_load' => sub {
70         $chg->load(relative_slot => "current",
71                    res_cb => $got_res);
72     });
73
74     $got_res = make_cb('got_res' => sub {
75         my ($err, $res) = @_;
76         ok(!$err, "no error loading relative slot 'current'")
77             or diag($err);
78         is($res->{'device'}->device_name, 'null:',
79             "returns correct device name");
80
81         $res->release(finished_cb => sub {
82             Amanda::MainLoop::quit();
83         });
84     });
85
86     # start the loop
87     $get_info->();
88     Amanda::MainLoop::run();
89 }
90
91 # eject is not implemented
92 {
93     my $try_eject = make_cb('try_eject' => sub {
94         $chg->eject(finished_cb => sub {
95             my ($err, $res) = @_;
96             chg_err_like($err,
97                 { type => 'failed', reason => 'notimpl' },
98                 "eject returns a failed/notimpl error");
99
100             Amanda::MainLoop::quit();
101         });
102     });
103
104     $try_eject->();
105     Amanda::MainLoop::run();
106 }