AFS-Command
view release on metacpan or search on metacpan
t/30pts_basic.t view on Meta::CPAN
#
# $Id: 30pts_basic.t,v 11.1 2004/11/18 13:31:39 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} =~ /\bpts\b/ ) {
$TestTotal = 0;
} elsif ( $AFS::Command::Tests::Config{AFS_COMMAND_CELLNAME} eq 'your.cell.name' ) {
$TestTotal = 0;
} else {
$TestTotal = 59;
}
print "1..$TestTotal\n";
}
END {print "not ok 1\n" unless $Loaded;}
use AFS::Command::PTS 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 $ptsgroup = $AFS::Command::Tests::Config{AFS_COMMAND_PTS_GROUP} || do {
print "not ok $TestCounter..$TestTotal\n";
die "Missing configuration variable AFS_COMMAND_PTS_GROUP\n";
};
my $ptsuser = $AFS::Command::Tests::Config{AFS_COMMAND_PTS_USER} || do {
print "not ok $TestCounter..$TestTotal\n";
die "Missing configuration variable AFS_COMMAND_PTS_USER\n";
};
my $binary = $AFS::Command::Tests::Config{AFS_COMMAND_BINARY_PTS} || 'pts';
#
# If the constructor fails, we're doomed.
#
my $pts = AFS::Command::PTS->new
(
command => $binary,
);
if ( ref $pts && $pts->isa("AFS::Command::PTS") ) {
print "ok $TestCounter\n";
$TestCounter++;
} else {
print "not ok $TestCounter..$TestTotal\n";
die "Unable to instantiate AFS::Command::PTS object\n";
}
#
# pts listmax
#
my $result = $pts->listmax
(
cell => $cell,
);
if ( ref $result && $result->isa("AFS::Object::PTServer") ) {
print "ok $TestCounter\n";
$TestCounter++;
} else {
print "not ok $TestCounter..$TestTotal\n";
die "Unable to call listmax:\n" . $pts->errors();
}
foreach my $attr ( qw( maxuserid maxgroupid ) ) {
if ( defined($result->$attr()) ) {
my $id = $result->$attr();
my $ok ='not ok';
if ( $attr eq 'maxuserid' ) {
$ok = 'ok' if $id > 0;
} else {
$ok = 'ok' if $id < 0;
}
print "$ok $TestCounter\n";
if ( $ok eq 'not ok' ) {
warn("pts->listmax attr '$attr' has the wrong sign (+/-)\n");
}
} else {
print "not ok $TestCounter\n";
warn("pts->listmax result has no attr '$attr'\n");
}
$TestCounter++;
}
#
# pts creategroup, createuser, examine
#
foreach my $name ( $ptsgroup, $ptsuser ) {
#
# First, let's make sure our test IDs aren't defined, so we can
# redefine them.
#
my $result = $pts->delete
(
nameorid => $name,
cell => $cell,
);
if ( $result ) {
print "ok $TestCounter\n";
} elsif ( defined($pts->errors()) && $pts->errors() =~ /unable to find entry/ ) {
print "ok $TestCounter\n";
} else {
print "not ok $TestCounter..$TestTotal\n";
die("Unable to delete the test pts id ($name), or verify it doesn't exist\n" .
Data::Dumper->Dump([$pts],['pts']));
}
$TestCounter++;
my $method = $name eq $ptsgroup ? 'creategroup' : 'createuser';
my $type = $name eq $ptsgroup ? 'Group' : 'User';
my $class = 'AFS::Object::' . ( $name eq $ptsgroup ? 'Group' : 'User' );
$result = $pts->$method
(
name => $name,
cell => $cell,
);
if ( ref $result && $result->isa("AFS::Object::PTServer") ) {
print "ok $TestCounter\n";
$TestCounter++;
} else {
print "not ok $TestCounter..$TestTotal\n";
die "Unable to call $method:\n" . $pts->errors();
}
my $byname = $name eq $ptsgroup ? 'getGroupByName' : 'getUserByName';
my $byid = $name eq $ptsgroup ? 'getGroupById' : 'getUserById';
my $getall = $name eq $ptsgroup ? 'getGroups' : 'getUsers';
my $entry = $result->$byname($name);
if ( ref $entry && $entry->isa($class) ) {
print "ok $TestCounter\n";
$TestCounter++;
my $id = $entry->id();
if ( $name eq $ptsgroup ) {
if ( $id < 0 ) {
print "ok $TestCounter\n";
} else {
print "not ok $TestCounter\n";
warn("Group $name doesn't have a negative id as expected\n");
}
} else {
if ( $id > 0 ) {
print "ok $TestCounter\n";
} else {
print "not ok $TestCounter\n";
warn("User $name doesn't have a positive id as expected\n");
}
}
$TestCounter++;
$entry = $result->$byid($id);
if ( ref $entry && $entry->isa($class) ) {
print "ok $TestCounter\n";
$TestCounter++;
my $othername = $entry->name();
if ( $name eq $othername ) {
print "ok $TestCounter\n";
} else {
print "not ok $TestCounter\n";
( run in 0.725 second using v1.01-cache-2.11-cpan-39bf76dae61 )