2 # Copyright (c) 2009-2012 Zmanda, Inc. All Rights Reserved.
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 # You should have received a copy of the GNU General Public License along
15 # with this program; if not, write to the Free Software Foundation, Inc.,
16 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # Contact information: Zmanda Inc, 465 S. Mathilda Ave., Suite 300
19 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
21 package Installcheck::Changer;
25 Installcheck::Changer - utilities for testing changers
29 use Installcheck::Changer;
34 { message => "expected msg", type => 'failure' },
35 "operation produces the expected error");
36 # or, just looking at the message
39 "operation produces the expected error");
44 The function C<chg_err_like> takes an C<Amanda::Changer::Error> object and a
45 hashref of expected values for that error object, and compares the two. The
46 values of this hashref can be regular expressions or strings. Alternately, the
47 function can take a regexp which is compared to the error's message. This
48 function is exported by default.
56 use vars qw( @ISA @EXPORT );
60 @EXPORT = qw(chg_err_like);
63 my ($err, $expected, $msg) = @_;
65 if (!defined($err) or !$err->isa("Amanda::Changer::Error")) {
67 diag("Expected an Amanda::Changer::Error object; got\n" . Dumper($err));
71 if (ref($expected) eq 'Regexp') {
72 like($err->{'message'}, $expected, $msg);
75 for my $key (qw( type reason message )) {
76 if (exists $expected->{$key}) {
77 if (!exists $err->{$key}) {
80 diag("expected a '$key' hash elt, but saw none");
84 my ($got, $exp) = ($err->{$key}, $expected->{$key});
85 if (ref($exp) eq "Regexp") {
89 diag("$key '$got' does not match '$exp'");
91 } elsif ($got ne $exp) {
94 diag("expected $key '$exp'; got $key '$got'");