I am trying to create a unit test for this error post subroutine shown below. This method takes in the error name and prints out the message which is a value located in each error. This is the code I have:
use constant {
# link included as a variable in this example
ERROR_AED => {
errorCode => 561,
message => {"this is an error. "},
tt => { template => 'disabled'},
link => 'www.error-fix.com',
},
};
sub error_post {
my($error) = @_;
printf ($error->{ message });
}
error_post(ERROR_AED);
This was my approach I'm pretty sure it's wrong I was attempting to verify the input values, or more generally verify that it was an error that was passed into the error_post method.
#verifying input values
sub test_error_post {
ok( defined $error, 'Should have an input value' ); # check that it's a constant
ok($error->isa(constant) , 'Error should be of type constant');
ok($error->errorCode), 'Should contain key errorCode');
ok($error->message), 'Should contain key message');
ok($error->tt), 'Should contain key tt');
ok($error->wiki_page) 'Should contain key wiki page');
}
I know this is probably a long way off.