This is just an example of one of the tests I run on an error. I want to edit this so that I can loop through a list of errors. Would I put these errors in to a hash and create a for loop to iterate through them. I'm not sure exactly how it's done. I will display the test and the error library below. Just need a small example to get me going.
Test file:
use lib('./t/lib/');
use Test::More tests => 3;
use ASC::Builder:Error;
#########################################################################################################
############## test for new() method in Error.pm - Test Case: HASH ####################################
#########################################################################################################
# error hash
my $error_hash = UNABLE_TO_PING_SWITCH_ERROR;
# error hash is passed into new and an error object is outputted
my $error_in = ASC::Builder::Error->new($error_hash);
# checks to see if the output object from new is an Error object
isa_ok($error_in, 'ASC::Builder::Error');
# checking that object can call the message() method
can_ok( $error_in, 'message');
# checks to see if the output message matches the message contained in the error hash(correct)
is($error_in->message(),( $error_hash->{message} ), 'Returns correct error message');
ErrorLibrary.pm
package ASC::Builder::ErrorLibrary;
use strict;
use warnings;
use parent 'Exporter';
# list of export error messages
our @EXPORT_OK = qw/
INCORRECT_CABLING_ERROR
UPDATE_IMAGE_ERROR
UNABLE_TO_PING_SWITCH_ERROR
/;
# error message list
use constant {
# wiki link included as a variable in this example
INCORRECT_CABLING_ERROR => {
code => "INCORRECT_CABLING_ERROR",
errorNum => 561,
category => 'Cabling Error',
message => "ToR cabling is not correct at T1.The uplinks must be cabled to exactly one t1 device group",
tt => { template => 'disabled'},
fatal => 1,
wiki_page =>'http://ift.tt/24f6RFS',
},
UPDATE_IMAGE_ERROR => {
code => "UPDATE_IMAGE_ERROR",
errorNum => 556,
category => 'Switch Error',
message => "Cannot determine switch model",
tt => { template => 'disabled'},
fatal => 1,
wiki_page =>'http://ift.tt/1Uc5pkK',
},
UNABLE_TO_PING_SWITCH_ERROR => {
code => "UNABLE_TO_PING_SWITCH_ERROR",
errorNum => 727,
category => 'Switch Error',
message => "Could not ping switch [% switch_ip %] in [% timeout %] seconds.",
tt => {template => 'disabled'},
fatal => 1,
wiki_page => 'http://ift.tt/1WHCR3s',
},
UNKNOWN_CLIENT_CERT_ID_ERROR => {
code => "UNKNOWN_CLIENT_CERT_ID_ERROR",
errorNum => 681,
category => 'Services Error',
message => "Unknown client certificate id: [% cert_id %]",
tt => { template => 'disabled'},
fatal => 1,
wiki_page =>'http://ift.tt/1Uc5pkM',
},
# add errors to this library
};
1;
I'm just not sure how to create my list. should I create of a list of with input , process and outputs to test against. I'm a bit confused.
Aucun commentaire:
Enregistrer un commentaire