is($last_log,$message,"Verified that we could write a log entry to journalctl by warning the user of incoming warnings and errors.");
### Anvil::Tools::Alert tests
# <none yet>
### Anvil::Tools::Convert tests
# cidr tests
is($anvil->Convert->cidr({cidr=>"fake"}),"","Verifying that Convert->cidr properly returned an empty string for a bad 'cidr' parameter.");
is($anvil->Convert->cidr({cidr=>"0"}),"0.0.0.0","Verifying that Convert->cidr properly returned '0.0.0.0' when given a 'cidr' parameter of '0'.");
is($anvil->Convert->cidr({cidr=>"1"}),"128.0.0.0","Verifying that Convert->cidr properly returned '128.0.0.0' when given a 'cidr' parameter of '1'.");
is($anvil->Convert->cidr({cidr=>"2"}),"192.0.0.0","Verifying that Convert->cidr properly returned '192.0.0.0' when given a 'cidr' parameter of '2'.");
is($anvil->Convert->cidr({cidr=>"3"}),"224.0.0.0","Verifying that Convert->cidr properly returned '224.0.0.0' when given a 'cidr' parameter of '3'.");
is($anvil->Convert->cidr({cidr=>"4"}),"240.0.0.0","Verifying that Convert->cidr properly returned '240.0.0.0' when given a 'cidr' parameter of '4'.");
is($anvil->Convert->cidr({cidr=>"5"}),"248.0.0.0","Verifying that Convert->cidr properly returned '248.0.0.0' when given a 'cidr' parameter of '5'.");
is($anvil->Convert->cidr({cidr=>"6"}),"252.0.0.0","Verifying that Convert->cidr properly returned '252.0.0.0' when given a 'cidr' parameter of '6'.");
is($anvil->Convert->cidr({cidr=>"7"}),"254.0.0.0","Verifying that Convert->cidr properly returned '254.0.0.0' when given a 'cidr' parameter of '7'.");
is($anvil->Convert->cidr({cidr=>"8"}),"255.0.0.0","Verifying that Convert->cidr properly returned '255.0.0.0' when given a 'cidr' parameter of '8'.");
is($anvil->Convert->cidr({cidr=>"9"}),"255.128.0.0","Verifying that Convert->cidr properly returned '255.128.0.0' when given a 'cidr' parameter of '9'.");
is($anvil->Convert->cidr({cidr=>"10"}),"255.192.0.0","Verifying that Convert->cidr properly returned '255.192.0.0' when given a 'cidr' parameter of '10'.");
is($anvil->Convert->cidr({cidr=>"11"}),"255.224.0.0","Verifying that Convert->cidr properly returned '255.224.0.0' when given a 'cidr' parameter of '11'.");
is($anvil->Convert->cidr({cidr=>"12"}),"255.240.0.0","Verifying that Convert->cidr properly returned '255.240.0.0' when given a 'cidr' parameter of '12'.");
is($anvil->Convert->cidr({cidr=>"13"}),"255.248.0.0","Verifying that Convert->cidr properly returned '255.248.0.0' when given a 'cidr' parameter of '13'.");
is($anvil->Convert->cidr({cidr=>"14"}),"255.252.0.0","Verifying that Convert->cidr properly returned '255.252.0.0' when given a 'cidr' parameter of '14'.");
is($anvil->Convert->cidr({cidr=>"15"}),"255.254.0.0","Verifying that Convert->cidr properly returned '255.254.0.0' when given a 'cidr' parameter of '15'.");
is($anvil->Convert->cidr({cidr=>"16"}),"255.255.0.0","Verifying that Convert->cidr properly returned '255.255.0.0' when given a 'cidr' parameter of '16'.");
is($anvil->Convert->cidr({cidr=>"17"}),"255.255.128.0","Verifying that Convert->cidr properly returned '255.255.128.0' when given a 'cidr' parameter of '17'.");
is($anvil->Convert->cidr({cidr=>"18"}),"255.255.192.0","Verifying that Convert->cidr properly returned '255.255.192.0' when given a 'cidr' parameter of '18'.");
is($anvil->Convert->cidr({cidr=>"19"}),"255.255.224.0","Verifying that Convert->cidr properly returned '255.255.224.0' when given a 'cidr' parameter of '19'.");
is($anvil->Convert->cidr({cidr=>"20"}),"255.255.240.0","Verifying that Convert->cidr properly returned '255.255.240.0' when given a 'cidr' parameter of '20'.");
is($anvil->Convert->cidr({cidr=>"21"}),"255.255.248.0","Verifying that Convert->cidr properly returned '255.255.248.0' when given a 'cidr' parameter of '21'.");
is($anvil->Convert->cidr({cidr=>"22"}),"255.255.252.0","Verifying that Convert->cidr properly returned '255.255.252.0' when given a 'cidr' parameter of '22'.");
is($anvil->Convert->cidr({cidr=>"23"}),"255.255.254.0","Verifying that Convert->cidr properly returned '255.255.254.0' when given a 'cidr' parameter of '23'.");
is($anvil->Convert->cidr({cidr=>"24"}),"255.255.255.0","Verifying that Convert->cidr properly returned '255.255.255.0' when given a 'cidr' parameter of '24'.");
is($anvil->Convert->cidr({cidr=>"25"}),"255.255.255.128","Verifying that Convert->cidr properly returned '255.255.255.128' when given a 'cidr' parameter of '25'.");
is($anvil->Convert->cidr({cidr=>"26"}),"255.255.255.192","Verifying that Convert->cidr properly returned '255.255.255.192' when given a 'cidr' parameter of '26'.");
is($anvil->Convert->cidr({cidr=>"27"}),"255.255.255.224","Verifying that Convert->cidr properly returned '255.255.255.224' when given a 'cidr' parameter of '27'.");
is($anvil->Convert->cidr({cidr=>"28"}),"255.255.255.240","Verifying that Convert->cidr properly returned '255.255.255.240' when given a 'cidr' parameter of '28'.");
is($anvil->Convert->cidr({cidr=>"29"}),"255.255.255.248","Verifying that Convert->cidr properly returned '255.255.255.248' when given a 'cidr' parameter of '29'.");
is($anvil->Convert->cidr({cidr=>"30"}),"255.255.255.252","Verifying that Convert->cidr properly returned '255.255.255.252' when given a 'cidr' parameter of '30'.");
is($anvil->Convert->cidr({cidr=>"31"}),"255.255.255.254","Verifying that Convert->cidr properly returned '255.255.255.254' when given a 'cidr' parameter of '31'.");
is($anvil->Convert->cidr({cidr=>"32"}),"255.255.255.255","Verifying that Convert->cidr properly returned '255.255.255.255' when given a 'cidr' parameter of '32'.");
is($anvil->Convert->cidr({subnet_mask=>"fake"}),"","Verifying that Convert->cidr properly returned an empty string for a bad 'subnet' parameter.");
is($anvil->Convert->cidr({subnet_mask=>"0.0.0.0"}),"0","Verifying that Convert->cidr properly returned '0' when given a 'subnet' parameter of '0.0.0.0'.");
is($anvil->Convert->cidr({subnet_mask=>"128.0.0.0"}),"1","Verifying that Convert->cidr properly returned '1' when given a 'subnet' parameter of '128.0.0.0'.");
is($anvil->Convert->cidr({subnet_mask=>"192.0.0.0"}),"2","Verifying that Convert->cidr properly returned '2' when given a 'subnet' parameter of '192.0.0.0'.");
is($anvil->Convert->cidr({subnet_mask=>"224.0.0.0"}),"3","Verifying that Convert->cidr properly returned '3' when given a 'subnet' parameter of '224.0.0.0'.");
is($anvil->Convert->cidr({subnet_mask=>"240.0.0.0"}),"4","Verifying that Convert->cidr properly returned '4' when given a 'subnet' parameter of '240.0.0.0'.");
is($anvil->Convert->cidr({subnet_mask=>"248.0.0.0"}),"5","Verifying that Convert->cidr properly returned '5' when given a 'subnet' parameter of '248.0.0.0'.");
is($anvil->Convert->cidr({subnet_mask=>"252.0.0.0"}),"6","Verifying that Convert->cidr properly returned '6' when given a 'subnet' parameter of '252.0.0.0'.");
is($anvil->Convert->cidr({subnet_mask=>"254.0.0.0"}),"7","Verifying that Convert->cidr properly returned '7' when given a 'subnet' parameter of '254.0.0.0'.");
is($anvil->Convert->cidr({subnet_mask=>"255.0.0.0"}),"8","Verifying that Convert->cidr properly returned '8' when given a 'subnet' parameter of '255.0.0.0'.");
is($anvil->Convert->cidr({subnet_mask=>"255.128.0.0"}),"9","Verifying that Convert->cidr properly returned '9' when given a 'subnet' parameter of '255.128.0.0'.");
is($anvil->Convert->cidr({subnet_mask=>"255.192.0.0"}),"10","Verifying that Convert->cidr properly returned '10' when given a 'subnet' parameter of '255.192.0.0'.");
is($anvil->Convert->cidr({subnet_mask=>"255.224.0.0"}),"11","Verifying that Convert->cidr properly returned '11' when given a 'subnet' parameter of '255.224.0.0'.");
is($anvil->Convert->cidr({subnet_mask=>"255.240.0.0"}),"12","Verifying that Convert->cidr properly returned '12' when given a 'subnet' parameter of '255.240.0.0'.");
is($anvil->Convert->cidr({subnet_mask=>"255.248.0.0"}),"13","Verifying that Convert->cidr properly returned '13' when given a 'subnet' parameter of '255.248.0.0'.");
is($anvil->Convert->cidr({subnet_mask=>"255.252.0.0"}),"14","Verifying that Convert->cidr properly returned '14' when given a 'subnet' parameter of '255.252.0.0'.");
is($anvil->Convert->cidr({subnet_mask=>"255.254.0.0"}),"15","Verifying that Convert->cidr properly returned '15' when given a 'subnet' parameter of '255.254.0.0'.");
is($anvil->Convert->cidr({subnet_mask=>"255.255.0.0"}),"16","Verifying that Convert->cidr properly returned '16' when given a 'subnet' parameter of '255.255.0.0'.");
is($anvil->Convert->cidr({subnet_mask=>"255.255.128.0"}),"17","Verifying that Convert->cidr properly returned '17' when given a 'subnet' parameter of '255.255.128.0'.");
is($anvil->Convert->cidr({subnet_mask=>"255.255.192.0"}),"18","Verifying that Convert->cidr properly returned '18' when given a 'subnet' parameter of '255.255.192.0'.");
is($anvil->Convert->cidr({subnet_mask=>"255.255.224.0"}),"19","Verifying that Convert->cidr properly returned '19' when given a 'subnet' parameter of '255.255.224.0'.");
is($anvil->Convert->cidr({subnet_mask=>"255.255.240.0"}),"20","Verifying that Convert->cidr properly returned '20' when given a 'subnet' parameter of '255.255.240.0'.");
is($anvil->Convert->cidr({subnet_mask=>"255.255.248.0"}),"21","Verifying that Convert->cidr properly returned '21' when given a 'subnet' parameter of '255.255.248.0'.");
is($anvil->Convert->cidr({subnet_mask=>"255.255.252.0"}),"22","Verifying that Convert->cidr properly returned '22' when given a 'subnet' parameter of '255.255.252.0'.");
is($anvil->Convert->cidr({subnet_mask=>"255.255.254.0"}),"23","Verifying that Convert->cidr properly returned '23' when given a 'subnet' parameter of '255.255.254.0'.");
is($anvil->Convert->cidr({subnet_mask=>"255.255.255.0"}),"24","Verifying that Convert->cidr properly returned '24' when given a 'subnet' parameter of '255.255.255.0'.");
is($anvil->Convert->cidr({subnet_mask=>"255.255.255.128"}),"25","Verifying that Convert->cidr properly returned '25' when given a 'subnet' parameter of '255.255.255.128'.");
is($anvil->Convert->cidr({subnet_mask=>"255.255.255.192"}),"26","Verifying that Convert->cidr properly returned '26' when given a 'subnet' parameter of '255.255.255.192'.");
is($anvil->Convert->cidr({subnet_mask=>"255.255.255.224"}),"27","Verifying that Convert->cidr properly returned '27' when given a 'subnet' parameter of '255.255.255.224'.");
is($anvil->Convert->cidr({subnet_mask=>"255.255.255.240"}),"28","Verifying that Convert->cidr properly returned '28' when given a 'subnet' parameter of '255.255.255.240'.");
is($anvil->Convert->cidr({subnet_mask=>"255.255.255.248"}),"29","Verifying that Convert->cidr properly returned '29' when given a 'subnet' parameter of '255.255.255.248'.");
is($anvil->Convert->cidr({subnet_mask=>"255.255.255.252"}),"30","Verifying that Convert->cidr properly returned '30' when given a 'subnet' parameter of '255.255.255.252'.");
is($anvil->Convert->cidr({subnet_mask=>"255.255.255.254"}),"31","Verifying that Convert->cidr properly returned '31' when given a 'subnet' parameter of '255.255.255.254'.");
is($anvil->Convert->cidr({subnet_mask=>"255.255.255.255"}),"32","Verifying that Convert->cidr properly returned '32' when given a 'subnet' parameter of '255.255.255.255'.");
like($anvil->Get->date_and_time(),qr/^\d\d\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d$/,"Verifying the current date and time is returned.");
like($anvil->Get->date_and_time({date_only=>1}),qr/^\d\d\d\d\/\d\d\/\d\d$/,"Verifying the current date alone is returned.");
like($anvil->Get->date_and_time({time_only=>1}),qr/^\d\d:\d\d:\d\d$/,"Verifying the current time alone is returned.");
like($anvil->Get->date_and_time({file_name=>1}),qr/^\d\d\d\d-\d\d-\d\d_\d\d-\d\d-\d\d$/,"Verifying the current date and time is returned in a file-friendly format.");
like($anvil->Get->date_and_time({file_name=>1,date_only=>1}),qr/^\d\d\d\d-\d\d-\d\d$/,"Verifying the current date only is returned in a file-friendly format.");
like($anvil->Get->date_and_time({file_name=>1,time_only=>1}),qr/^\d\d-\d\d-\d\d$/,"Verifying the current time only is returned in a file-friendly format.");
# We can't be too specific because the user's TZ will shift the results
like($anvil->Get->date_and_time({use_time=>1234567890}),qr/2009\/02\/1[34] \d\d:\d\d:\d\d$/,"Verified that a specific unixtime returned the expected date.");
like($anvil->Get->date_and_time({use_time=>1234567890,offset=>31536000}),qr/2010\/02\/1[34] \d\d:\d\d:\d\d$/,"Verified that a specific unixtime with a one year in the future offset returned the expected date.");
like($anvil->Get->date_and_time({use_time=>1234567890,offset=>-31536000}),qr/2008\/02\/1[34] \d\d:\d\d:\d\d$/,"Verified that a specific unixtime with a one year in the past offset returned the expected date.");
# host_uuid
like($anvil->Get->host_uuid,qr/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/,"Verifying ability to read host uuid.");
### TODO: How to test Get->switches?
# uuid
like($anvil->Get->uuid,qr/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/,"Verifying ability to generate a random uuid.");
### Anvil::Tools::Log tests
# entry is tested at the start of this test suite.
# language
is($anvil->Log->language,"en_CA","Verifying the default log language is 'en_CA'.");
$anvil->Log->language({set=>"jp"});
is($anvil->Log->language,"jp","Verifying the log language was changed to 'jp'.");
$anvil->Log->language({set=>"en_CA"});
is($anvil->Log->language,"en_CA","Verifying the log language is back to 'en_CA'.");
# log_level
is($anvil->Log->level,"1","Verifying the default log level is '1'.");
$anvil->Log->level({set=>0});
is($anvil->Log->level,"0","Verifying the log level changed to '0'.");
$anvil->Log->level({set=>1});
is($anvil->Log->level,"1","Verifying the log level changed to '1'.");
$anvil->Log->level({set=>2});
is($anvil->Log->level,"2","Verifying the log level changed to '2'.");
$anvil->Log->level({set=>3});
is($anvil->Log->level,"3","Verifying the log level changed to '3'.");
$anvil->Log->level({set=>4});
is($anvil->Log->level,"4","Verifying the log level changed to '4'.");
$anvil->Log->level({set=>"foo"});
is($anvil->Log->level,"4","Verifying the log level stayed at '4' with bad input.");
$anvil->Log->level({set=>1});
is($anvil->Log->level,"1","Verifying the log level changed back to '1'.");
# secure
is($anvil->Log->secure,"0","Verifying that logging secure messages is disabled by default.");
$anvil->Log->secure({set=>"foo"});
is($anvil->Log->secure,"0","Verifying that logging secure messages stayed disabled on bad input.");
$anvil->Log->secure({set=>1});
is($anvil->Log->secure,"1","Verifying that logging secure messages was enabled.");
$anvil->Log->secure({set=>0});
is($anvil->Log->secure,"0","Verifying that logging secure messages was disabled again.");
is($mode,"4755","Verifying that 'Storage->change_mode' was able to change the mode of the test file (including setting the setuid and setgid sticky bits).");
is($directory_mode,"0757","Verifying that 'Storage->create_directory' created a directory with the requested mode.");
is($directory_user_name,$use_user,"Verifying that 'Storage->create_directory' created a directory with the requested owner.");
is($directory_group_name,$use_group,"Verifying that 'Storage->create_directory' created a directory with the requested group.");
# read_config
$anvil->data->{foo}{bar}{a}="test";
is($anvil->Storage->read_config({file=>"Anvil/test.conf"}),0,"Verifying that 'Storage->read_config' successfully found 'Anvil/test.conf'.");
is($anvil->Storage->read_config({file=>""}),1,"Verifying that 'Storage->read_config' returns '1' when called without a 'file' parameter being set.");
is($anvil->Storage->read_config({file=>"Anvil/moo.conf"}),2,"Verifying that 'Storage->read_config' returns '2' when the non-existent 'Anvil/moo.conf' is passed.");
cmp_ok($anvil->data->{foo}{bar}{a},'eq','I am "a"',"Verifying that 'Anvil/test.conf's 'foo::bar::a' overwrote an earlier set value.");
cmp_ok($anvil->data->{foo}{bar}{b},'eq','I am "b", split with tabs and having trailing spaces.',"Verifying that 'Anvil/test.conf's 'foo::bar::b' has whitespaces removed as expected.");
cmp_ok($anvil->data->{foo}{baz}{1},'eq','This is \'1\' with no spaces',"Verifying that 'Anvil/test.conf's 'foo::baz::1' parsed without spaces around '='.");
cmp_ok($anvil->data->{foo}{baz}{2},'eq','I had a $dollar = sign and split with tabs.',"Verifying that 'Anvil/test.conf's 'foo::baz::2' had no trouble with a '\$' and '=' characters in the string.");
# read_file was tested earlier.
# read_mode was tested earlier.
# search_directories
my$array1=$anvil->Storage->search_directories;
my$a1_count=@{$array1};
cmp_ok($a1_count,'>',0,"Verifying that Storage->search_directories has at least one entry. Found: [$a1_count] directories.");
cmp_ok($a2_count,'==',2,"Verifying that Storage->search_directories now has 2 entries from a passed in CSV, testing that the list changed and a fake directory was dropped.");
cmp_ok($a3_count,'==',3,"Verifying that Storage->search_directories now has 3 entries from a passed in array reference, verifying that the list changed again.");
cmp_ok($a4_count,'==',$a1_count,"Verifying that Storage->search_directories has the original number of directories: [$a4_count] after being called with an invalid 'directories' parameter, showing that it reset properly.");
is($test2_template,"<!-- start: [/tmp/anvil.html] -> [test1] -->\nThis is test template #1.\n<!-- end: [/tmp/anvil.html] -> [test1] -->\n","Verifying that 'Template->get' was able to read a test template with the source in HTML comments.");
is($test3_template,"This is test template #2. It has a replacement: [boo!].\n","Verifying that 'Template->get' was able to read a test template with a variable insertion.");
is($anvil->Template->skin,"alteeve","Verifying that 'Template->skin' is initially set to 'alteeve'.");
$anvil->Template->skin({fatal=>0,set=>"test"});# We disable fatal because there may be no skin directory yet.
is($anvil->Template->skin,"test","Verifying that 'Template->skin' was changed to 'test'.");
my$clean_string2="A line with spaces at the end only ";
my$clean_string3=" A line with spaces in the front only";
my$clean_string4="A line with spaces in the middle only";
is($anvil->Words->clean_spaces({string=>$clean_string1}),"A line with spaces all over","Verifying that 'Words->clean_spaces' cleaned up a string with random spaces.");
is($anvil->Words->clean_spaces({string=>$clean_string2}),"A line with spaces at the end only","Verifying that 'Words->clean_spaces' cleaned up a string spaces at the end of a string.");
is($anvil->Words->clean_spaces({string=>$clean_string3}),"A line with spaces in the front only","Verifying that 'Words->clean_spaces' cleaned up a string with spaces in the front only.");
is($anvil->Words->clean_spaces({string=>$clean_string4}),"A line with spaces in the middle only","Verifying that 'Words->clean_spaces' cleaned up a string with spaces in the middle only.");
# key
is($anvil->Words->key({key=>"t_0001"}),"Test replace: [#!variable!test!#].","Verifying that 'Words->key' returned the Canadian English 't_0001' string.");
is($anvil->Words->key({key=>"t_0001",language=>"jp"}),"テスト いれかえる: [#!variable!test!#]。","Verifying that 'Words->read' returned the Japanese 't_0001' string.");
is($anvil->Words->key({key=>"bad_key"}),"#!not_found!#","Verified that 'Words->key' returns '#!not_found!#' for a bad key.");
is($anvil->Words->key({key=>"t_0003",language=>"jp"}),"#!not_found!#","Verifying that 'Words->read' returned '#!not_found!#' for the missing 't_0003' key.");
# language
is($anvil->Words->language,"en_CA","Verifying the default words language is 'en_CA'.");
$anvil->Words->language({set=>"jp"});
is($anvil->Words->language,"jp","Verifying the words language was changed to 'jp'.");
$anvil->Words->language({set=>"en_CA"});
is($anvil->Words->language,"en_CA","Verifying the words language is back to 'en_CA'.");
# read
### NOTE: At this time, we don't test for unreadable files (rc = 3) or general read faults as set by XML::Simple (rc = 4).
is($anvil->Words->read({file=>$anvil->data->{path}{words}{'words.xml'}}),0,"Verifying that 'Words->read' properly returned '0' when asked to read the Anvil::Tools's words file.");
is($anvil->Words->read({file=>''}),1,"Verifying that 'Words->read' properly returned '1' when asked to read a works file without a file being passed.");
is($anvil->Words->read({file=>'/tmp/dummy.xml'}),2,"Verifying that 'Words->read' properly returned '2' when asked to read a non-existent file.");