openafs/tests/auth/writeoldkey-t
Mark Vitale fc5341d7ee tests: Cleanup auth/writeoldkey-t temp directory
Commit cbc5c4b51f 'tests: Modernize writekeyfile.c' introduced
writeoldkey-t and specified CLEANUP for its afs_XXXXX temporary work
directory.  However, Perl will not perform CLEANUP if the script is
still in that directory at exit.  Therefore writeoldkey-t leaves behind
an afs_XXXXX temp directory for each run.

Modify writeoldkey-t to cd back into 'tests' before exit, so that
CLEANUP will work as intended.

[mmeffie: save the cwd before cd to the temp dir]

Change-Id: Ida723f9bfca05cc96acf189156d13c8607d210f4
Reviewed-on: https://gerrit.openafs.org/15724
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Mark Vitale <mvitale@sinenomine.net>
Reviewed-by: Cheyenne Wills <cwills@sinenomine.net>
Reviewed-by: Michael Meffie <mmeffie@sinenomine.net>
2024-06-24 15:10:43 -04:00

45 lines
1.0 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 Test::More;
use File::Temp qw/tempdir/;
use Cwd qw/abs_path getcwd/;
use File::Compare;
use Sys::Hostname;
use Socket;
# Run tests/auth/writekeyfile, and check that the KeyFile that it generates
# matches what we expect.
if (!defined(gethostbyname(hostname()))) {
# writekeyfile needs a hostname to generate a config dir
plan skip_all => 'Cannot resolve hostname';
}
plan tests => 1;
my $cmd = obj_path("tests/auth/writekeyfile");
$cmd = abs_path($cmd);
my $keyfile = src_path("tests/auth/KeyFile.short");
$keyfile = abs_path($keyfile);
my $origdir = getcwd();
my $dir = tempdir('afs_XXXXXX', CLEANUP => 1);
chdir($dir)
or die("chdir $dir failed: $?");
system($cmd) == 0
or die("$cmd failed: $?");
ok(compare("KeyFile", $keyfile) == 0,
"writekeyfile generates expected KeyFile");
# The cleanup handler needs to run in the original directory.
chdir($origdir)
or die("chdir $origdir failed: $?");