openafs/tests/ptserver/pt_util-t
Andrew Deason d731d3c5bc tests: Add existing-database test for pt_util
Our current tests for pt_util use pt_util to generate a prdb, and then
check the output of pt_util against that created database. Add a new
test that runs pt_util against an existing database (with the same
test data), to make sure that pt_util is still using the same db
format.

Change-Id: I4dbe7f3b5080ee6ff1f9509992b5686fc8381da0
Reviewed-on: https://gerrit.openafs.org/14801
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>
2021-10-08 00:05:02 -04:00

60 lines
1.6 KiB
Perl
Executable File

#!/usr/bin/env perl
use strict;
use warnings;
use lib $ENV{C_TAP_SOURCE} . "/tests-lib/perl5";
use afstest qw(src_path obj_path);
use File::Basename;
use File::Temp qw(tempfile);
use Test::More tests=>3;
my $pt_util = obj_path("src/ptserver/pt_util");
(undef, my $prdb_tmp) = tempfile("prdbtest.XXXXXX", TMPDIR => 1, UNLINK => 1);
my $prdb_test = src_path("tests/ptserver/db.prtiny/prdb.DB0");
my $instructions = <<EOF;
admin 128/20 1 -204 -204
system:administrators 130/20 -204 -204 -204
admin 1
EOF
my $expected = <<EOF;
admin 128/20 1 -204 -204
anonymous 128/20 32766 -204 -204
system:backup 2/0 -205 -204 -204
system:administrators 130/20 -204 -204 -204
admin 1
system:ptsviewers 2/0 -203 -204 -204
system:authuser 2/0 -102 -204 -204
system:anyuser 2/0 -101 -204 -204
EOF
my $fh;
my $output;
open $fh, '|-', "$pt_util", '-w', '-p', $prdb_tmp
or die "Failed to start pt_util for DB creation\n";
print $fh $instructions;
close($fh)
or die "pt util failed while creating DB\n";
open $fh, '-|', "$pt_util", '-p', $prdb_tmp,
'-user', '-group', '-members'
or die "Failed to start pt_util for DB reading\n";
$output = join('', readline($fh));
close($fh)
or die "pt_util failed while reading from $prdb_tmp\n";
is($output, $expected, "pt_util produced expected output for generated db");
open $fh, '-|', "$pt_util", '-p', $prdb_test,
'-user', '-group', '-members'
or die "Failed to start pt_util for DB reading\n";
$output = join('', readline($fh));
close($fh)
or die "pt_util failed while reading from $prdb_test\n";
is($output, $expected, "pt_util produced expected output for test db");
ok(1, "Completed sucessfully");