AFS-Command
view release on metacpan or search on metacpan
t/20fs_basic.t view on Meta::CPAN
#
# $Id: 20fs_basic.t,v 11.1 2004/11/18 13:31:37 wpm Exp $
#
# (c) 2003-2004 Morgan Stanley and Co.
# See ..../src/LICENSE for terms of distribution.
#
# print STDERR Data::Dumper->Dump([$vos],['vos']);
use strict;
use English;
use Data::Dumper;
use vars qw(
$TestCounter
$TestTotal
$Loaded
);
BEGIN {
require "./util/lib/parse_config";
}
BEGIN {
$| = 1;
if ( $AFS::Command::Tests::Config{AFS_COMMAND_DISABLE_TESTS} =~ /\bfs\b/ ) {
$TestTotal = 0;
} elsif ( $AFS::Command::Tests::Config{AFS_COMMAND_CELLNAME} eq 'your.cell.name' ) {
$TestTotal = 0;
} else {
$TestTotal = 124;
}
print "1..$TestTotal\n";
}
END {print "not ok 1\n" unless $Loaded;}
use AFS::Command::FS 1.99;
$Loaded = 1;
$TestCounter = 1;
print "ok $TestCounter\n";
$TestCounter++;
exit 0 unless $TestTotal;
my $cell = $AFS::Command::Tests::Config{AFS_COMMAND_CELLNAME} || do {
print "not ok $TestCounter..$TestTotal\n";
die "Missing configuration variable AFS_COMMAND_CELLNAME\n";
};
my $pathafs = $AFS::Command::Tests::Config{AFS_COMMAND_PATHNAME_AFS} || do {
print "not ok $TestCounter..$TestTotal\n";
die "Missing configuration variable AFS_COMMAND_PATHNAME_AFS\n";
};
my $pathnotafs = "/var/tmp";
my $pathbogus = "/this/does/not/exist";
my $binary = $AFS::Command::Tests::Config{AFS_COMMAND_BINARY_FS} || 'fs';
#
# If the constructor fails, we're doomed.
#
my $fs = AFS::Command::FS->new
(
command => $binary,
);
if ( ref $fs && $fs->isa("AFS::Command::FS") ) {
print "ok $TestCounter\n";
$TestCounter++;
} else {
print "not ok $TestCounter..$TestTotal\n";
t/20fs_basic.t view on Meta::CPAN
$TestCounter++;
$result = $fs->checkservers
(
interval => 0,
);
if ( ref $result && $result->isa("AFS::Object::CacheManager") ) {
print "ok $TestCounter\n";
$TestCounter++;
} else {
print "not ok $TestCounter..$TestTotal\n";
die "Unable to call checkservers:\n" . $fs->errors();
}
if ( $result->interval() =~ /^\d+$/ ) {
print "ok $TestCounter\n";
} else {
print "not ok $TestCounter\n";
warn("Not an integer: fs->checkservers->interval()\n");
}
$TestCounter++;
#
# All the common _paths_method methods
#
my $paths = [ $pathafs, $pathnotafs, $pathbogus ];
my %pathops =
(
diskfree => [qw( volname total used avail percent )],
examine => [qw( volname total avail id quota )],
listquota => [qw( volname quota used percent partition )],
quota => [qw( percent )],
storebehind => [qw( asynchrony )],
whereis => [qw( hosts )],
whichcell => [qw( cell )],
);
foreach my $pathop ( keys %pathops ) {
unless ( $fs->supportsOperation($pathop) ) {
my $total = scalar(@{$pathops{$pathop}}) + 2;
$total++ if $pathop eq 'storebehind';
for ( my $count = 1 ; $count <= $total ; $count++ ) {
print "ok $TestCounter # skipping... fs->$pathop() is unsupported \n";
$TestCounter++;
}
next;
}
$result = $fs->$pathop
(
( $pathop eq 'storebehind' ? 'files' : 'path' ) => $paths,
);
if ( ref $result && $result->isa("AFS::Object::CacheManager") ) {
print "ok $TestCounter\n";
$TestCounter++;
} else {
print "not ok $TestCounter..$TestTotal\n";
die("Unable to call fs->$pathop:\n" . $fs->errors() .
Data::Dumper->Dump([$fs],['fs']));
}
if ( $pathop eq 'storebehind' ) {
if ( defined($result->asynchrony()) ) {
print "ok $TestCounter\n";
} else {
print "not ok $TestCounter\n";
warn("Result object for fs->storebehind() has no attr 'asynchrony'\n");
}
} else {
print "ok $TestCounter\n";
}
$TestCounter++;
foreach my $pathname ( @$paths ) {
my $path = $result->getPath($pathname);
if ( ref $path && $path->isa("AFS::Object::Path") ) {
print "ok $TestCounter\n";
$TestCounter++;
if ( $pathname eq $pathafs ) {
foreach my $attr ( @{$pathops{$pathop}} ) {
if ( defined($path->$attr()) ) {
print "ok $TestCounter\n";
} else {
print "not ok $TestCounter\n";
warn("Path object for '$pathname' has no attr '$attr'\n");
}
$TestCounter++;
}
} else {
my $ok = 'ok';
unless ( $path->error() ) {
warn("Pathname '$pathname' should have given an error()\n");
$ok = 'not ok';
}
for ( my $count = 1 ; $count <= scalar(@{$pathops{$pathop}}) ; $count++ ) {
print "$ok $TestCounter\n";
$TestCounter++;
}
}
} else {
warn("Unable to retreive path object for '$pathname' from fs->$pathop()\n");
for ( my $count = 1 ; $count <= (scalar(@{$pathops{$pathop}})+1) ; $count++ ) {
print "not ok $TestCounter\n";
$TestCounter++;
}
}
}
}
#
# fs exportafs -- this one is hard to really test, since we can't
# verify all the parsing unless it is actually supported and enabled,
# so fake it.
( run in 0.242 second using v1.01-cache-2.11-cpan-a5abf4f5562 )