2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-09-04 12:07:56 +00:00

test(utils): reuse repository file helpers

This commit is contained in:
Vinícius Ferrão
2026-08-26 12:04:14 -03:00
parent 0c0803d83a
commit 762e67d6cc
2 changed files with 10 additions and 17 deletions
+6 -11
View File
@@ -2,23 +2,20 @@ use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../lib";
use lib "$FindBin::Bin/../../perl-xCAT";
use Cwd qw/getcwd/;
use File::Path qw/make_path/;
use File::Slurper qw/write_text/;
use File::Temp qw/tempdir/;
use Test::More;
use xCAT::CommandUtils;
my $command_utils_source = "$FindBin::Bin/../../perl-xCAT/xCAT/CommandUtils.pm";
open( my $source_fh, '<', $command_utils_source )
or die "Unable to read $command_utils_source: $!";
my $source = do { local $/; <$source_fh> };
close($source_fh) or die "Unable to close $command_utils_source: $!";
like(
$source,
qr/my \@SYSTEM_FALLBACK_DIRS = qw\(\s*\/usr\/sbin\s*\/usr\/bin\s*\/sbin\s*\/bin\s*\);/s,
is_deeply(
\@xCAT::CommandUtils::SYSTEM_FALLBACK_DIRS,
[qw(/usr/sbin /usr/bin /sbin /bin)],
'the built-in system fallback order matches the replaced callers'
);
@@ -30,9 +27,7 @@ make_path( $first_dir, $second_dir, $fallback_dir, "$root/relative" );
sub write_executable {
my ($path) = @_;
open( my $fh, '>', $path ) or die "Unable to write $path: $!";
print {$fh} "#!/bin/sh\nexit 0\n";
close($fh) or die "Unable to close $path: $!";
write_text( $path, "#!/bin/sh\nexit 0\n" );
chmod 0755, $path or die "Unable to make $path executable: $!";
return $path;
}
+4 -6
View File
@@ -4,12 +4,14 @@ use warnings;
no warnings 'once';
use FindBin;
use lib "$FindBin::Bin/../lib";
use lib "$FindBin::Bin/../../perl-xCAT";
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
use File::Temp qw(tempdir);
use Socket ();
use Test::More;
use XCAT::Test::File qw(repo_path);
BEGIN {
package xCAT::Table;
@@ -81,12 +83,8 @@ require xCAT::Utils;
*xCAT::Utils::runcmd = sub { return; };
}
my $source_dhcp_plugin = "$FindBin::Bin/../../xCAT-server/lib/xcat/plugins/dhcp.pm";
if ( -f $source_dhcp_plugin ) {
require $source_dhcp_plugin;
} else {
require xCAT_plugin::dhcp;
}
my $source_dhcp_plugin = repo_path('xCAT-server/lib/xcat/plugins/dhcp.pm');
require $source_dhcp_plugin;
require xCAT::DHCP::Backend::Kea;
{