mirror of
https://git.proxmox.com/git/pve-installer
synced 2025-04-28 12:28:21 +00:00
test: add test for kernel commandline parsing
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
This commit is contained in:
parent
470af1d60e
commit
9a1494bad8
@ -11,7 +11,7 @@ use Proxmox::Log;
|
||||
use Proxmox::Install::ISOEnv;
|
||||
use Proxmox::Sys::Net;
|
||||
|
||||
my sub parse_kernel_cmdline {
|
||||
sub parse_kernel_cmdline {
|
||||
my ($cfg) = @_;
|
||||
|
||||
my $cmdline = Proxmox::Install::RunEnv::get('kernel_cmdline');
|
||||
|
@ -3,7 +3,8 @@ all:
|
||||
export PERLLIB=..
|
||||
|
||||
.PHONY: check
|
||||
check: test-zfs-arc-max test-run-command test-parse-fqdn test-ui2-stdio test-zfs-get-pool-list
|
||||
check: test-zfs-arc-max test-run-command test-parse-fqdn test-ui2-stdio \
|
||||
test-zfs-get-pool-list test-parse-kernel-cmdline
|
||||
|
||||
.PHONY: test-zfs-arc-max
|
||||
test-zfs-arc-max:
|
||||
@ -24,3 +25,7 @@ test-ui2-stdio:
|
||||
.PHONY: test-zfs-get-pool-list
|
||||
test-zfs-get-pool-list:
|
||||
./zfs-get-pool-list.pl
|
||||
|
||||
.PHONY: test-parse-kernel-cmdline
|
||||
test-parse-kernel-cmdline:
|
||||
./parse-kernel-cmdline.pl
|
||||
|
62
test/parse-kernel-cmdline.pl
Executable file
62
test/parse-kernel-cmdline.pl
Executable file
@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Test::More;
|
||||
use Test::MockModule qw(strict);
|
||||
|
||||
use Proxmox::Install::RunEnv;
|
||||
use Proxmox::Install::Config qw(parse_kernel_cmdline);
|
||||
|
||||
my $proxmox_install_runenv = Test::MockModule->new('Proxmox::Install::RunEnv');
|
||||
my $proxmox_install_isoenv = Test::MockModule->new('Proxmox::Install::ISOEnv');
|
||||
|
||||
$proxmox_install_isoenv->redefine(
|
||||
get => sub {
|
||||
my ($k) = @_;
|
||||
return { product => 'pve' } if !defined($k);
|
||||
die "iso environment key $k not mocked!\n";
|
||||
},
|
||||
);
|
||||
|
||||
my sub mock_kernel_cmdline {
|
||||
my ($cmdline) = @_;
|
||||
|
||||
$proxmox_install_runenv->redefine(
|
||||
get => sub {
|
||||
my ($k) = @_;
|
||||
return $cmdline if $k eq 'kernel_cmdline';
|
||||
die "iso environment key $k not mocked!\n";
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
sub is_parsed {
|
||||
my ($cmdline, $expected) = @_;
|
||||
|
||||
mock_kernel_cmdline($cmdline);
|
||||
my $cfg = Proxmox::Install::Config::parse_kernel_cmdline({});
|
||||
|
||||
is($cfg->{target_cmdline}, $expected, "filtered kernel commandline matched expected: ${expected}");
|
||||
}
|
||||
|
||||
is_parsed(
|
||||
'BOOT_IMAGE=/vmlinuz-6.8.12-1-pve root=/dev/mapper/pve-root ro quiet',
|
||||
''
|
||||
);
|
||||
|
||||
is_parsed(
|
||||
'BOOT_IMAGE=/vmlinuz-6.8.12-1-pve root=/dev/mapper/pve-root ro= quiet',
|
||||
'ro='
|
||||
);
|
||||
|
||||
is_parsed(
|
||||
'a BOOT_IMAGE=/vmlinuz-6.8.12-1-pve b root=/dev/mapper/pve-root c ro d quiet e',
|
||||
'a b c d e'
|
||||
);
|
||||
|
||||
is_parsed('proxmox-foo foo=bar proxtui', 'foo=bar');
|
||||
is_parsed('proxmox-foo nomodeset quiet', 'nomodeset');
|
||||
|
||||
done_testing();
|
Loading…
Reference in New Issue
Block a user