I use the perl Test framework to test lots-a-things. These are all crude test examples below -
# check webservice
like(
`lynx http://tiago.com -head -dump`,
qr/200 OK/,
'HEAD request using lynx'
);
# disk space
for (`df`)
{
my ($filesystem, $use) = /^(\S+) .+ (\d+)%/;
next unless ($filesystem && $use);
ok($use < 70, "$use \%filesystem");
}
# running daemons
my @ps = `ps -e`;
for my $daemon (qw(crond syslogd ntpd))
{
my $cnt = grep /$daemon/, @ps;
ok($cnt, "$daemon ($cnt)");
}
# software version
like(
`nmap --version`,
qr/\W3\.\d/,
'nmap version test'
);
# binaries and path
for my $bin ('ping','kill','pod2text', 'nslookup', 'tail')
{
my $loc = `which $bin`;
chomp $loc;
ok(stat($loc), $loc);
ok(-x _, 'executable by effective uid/gid');
}
# ping the machine
$ip = '66.39.54.27';
my $ret = join('', `ping -c 5 -W 1 $ip`);
like($ret, qr/ 0\% packet loss/, 'packet loss');
+
# DNS
$ip = '66.39.54.27';
$name = 'perlmonks.org';
like(`host $ip`, qr/$name/, 'DNS');
like(`host $name`, qr/$ip/, 'reverse DNS');
It's also not hard to make other languages output in the format usable by Test::Harness, so incidently, if anyone care to make a shell library of functions that mimic the Test::More module, drop me a note, I'm interested.
Tiago
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.