tests: Introduce afstest.pm
[openafs.git] / tests / auth / writeoldkey-t
1 #!/usr/bin/env perl
2
3 use strict;
4 use warnings;
5 use lib $ENV{C_TAP_SOURCE} . "/tests-lib/perl5";
6
7 use afstest qw(src_path obj_path);
8 use Test::More;
9 use File::Temp qw/tempdir/;
10 use Cwd qw/abs_path/;
11 use File::Compare;
12 use Sys::Hostname;
13 use Socket;
14
15 # Run tests/auth/writekeyfile, and check that the KeyFile that it generates
16 # matches what we expect.
17
18 if (!defined(gethostbyname(hostname()))) {
19     # writekeyfile needs a hostname to generate a config dir
20     plan skip_all => 'Cannot resolve hostname';
21 }
22 plan tests => 1;
23
24 my $cmd = obj_path("tests/auth/writekeyfile");
25 $cmd = abs_path($cmd);
26
27 my $keyfile = src_path("tests/auth/KeyFile.short");
28 $keyfile = abs_path($keyfile);
29
30 my $dir = tempdir('afs_XXXXXX', CLEANUP => 1);
31
32 chdir($dir)
33     or die("chdir $dir failed: $?");
34
35 system($cmd) == 0
36     or die("$cmd failed: $?");
37
38 ok(compare("KeyFile", $keyfile) == 0,
39    "writekeyfile generates expected KeyFile");