AFS-Command

 view release on metacpan or  search on metacpan

t/30pts_basic.t  view on Meta::CPAN

} 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 {



( run in 0.398 second using v1.01-cache-2.11-cpan-39bf76dae61 )