1 # Copyright (c) 2008-2012 Zmanda, Inc. All Rights Reserved.
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.
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
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
17 # Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
20 use Test::More tests => 6;
25 use lib "@amperldir@";
26 use Installcheck::Config;
27 use Installcheck::Changer;
32 use Amanda::Config qw( :init :getconf config_dir_relative );
35 # set up debugging so debug output doesn't interfere with test results
36 Amanda::Debug::dbopen("installcheck");
37 Installcheck::log_test_output();
39 # and disable Debug's die() and warn() overrides
40 Amanda::Debug::disable_die_override();
42 my $testconf = Installcheck::Config->new();
45 my $cfg_result = config_init($CONFIG_INIT_EXPLICIT_NAME, 'TESTCONF');
46 if ($cfg_result != $CFGERR_OK) {
47 my ($level, @errors) = Amanda::Config::config_errors();
48 die(join "\n", @errors);
51 my $chg = Amanda::Changer->new("chg-single:null:/foo");
52 die "$chg" if $chg->isa("Amanda::Changer::Error");
56 my ($get_info, $get_res, $got_res, $got_second_res);
58 $get_info = make_cb('get_info' => sub {
59 $chg->info(info_cb => $get_res, info => [ 'num_slots', 'fast_search' ]);
62 $get_res = make_cb('get_res' => sub {
65 die($err) if defined($err);
67 is($results{'num_slots'}, 1, "info() returns the correct num_slots");
68 is($results{'fast_search'}, 0, "info() returns the correct fast_slots");
70 $chg->load(relative_slot => "current",
74 $got_res = make_cb('got_res' => sub {
76 ok(!$err, "no error loading relative slot 'current'")
78 is($res->{'device'}->device_name(), 'null:/foo',
79 "returns correct device name");
81 $held_res = $res; # hang onto it while loading another slot
83 $chg->load(label => "FOO!",
84 res_cb => $got_second_res);
87 $got_second_res = make_cb('got_second_res' => sub {
90 { message => qr{'null:/foo' is already reserved},
92 reason => 'volinuse' },
93 "second simultaneous reservation rejected");
95 # release the first reservation
96 $held_res->release(finished_cb => sub {
100 Amanda::MainLoop::quit();
106 Amanda::MainLoop::run();
110 $chg = Amanda::Changer->new("chg-single:bogus:device");
112 "chg-single: error opening device 'bogus:device': Device type bogus is not known.",
113 "bogus device name detected early");