[PATCH pve-storage v1 40/54] test: parse volname: modernize code

Max R. Carrara
2026-04-22T11:19:26Z

Modernize the existing code in `parse_volname_test.pm` while leaving
the tests unchanged otherwise.

In particular,
- move the test execution code into its own subroutine
- add and call a `main()` subroutine
- declare `use v5.36;` instead of `use strict;` and `use warnings;`
- fix a handful of typos
- adapt the code style to fit our more modern style guide

Signed-off-by: Max R. Carrara <m.carrara@proxmox.com>
---
src/test/parse_volname_test.pm | 79 ++++++++++++++++++----------------
1 file changed, 43 insertions(+), 36 deletions(-)

diff --git a/src/test/parse_volname_test.pm b/src/test/parse_volname_test.pm
index 2ff4c6d0..a03ac163 100644
--- a/src/test/parse_volname_test.pm
+++ b/src/test/parse_volname_test.pm
@@ -1,7 +1,6 @@
package PVE::Storage::TestParseVolname;

-use strict;
-use warnings;
+use v5.36;

use lib qw(..);

@@ -147,24 +146,24 @@ my $tests = [
expected => ['import', 'import.ovf', undef, undef, undef, undef, 'ovf'],
},
{
- description => "Import, innner file of ova",
+ description => "Import, inner file of ova",
volname => 'import/import.ova/disk.qcow2',
expected =>
['import', 'import.ova/disk.qcow2', undef, undef, undef, undef, 'ova+qcow2'],
},
{
- description => "Import, innner file of ova",
+ description => "Import, inner file of ova",
volname => 'import/import.ova/disk.vmdk',
expected => ['import', 'import.ova/disk.vmdk', undef, undef, undef, undef, 'ova+vmdk'],
},
{
- description => "Import, innner file of ova with whitespace in name",
+ description => "Import, inner file of ova with whitespace in name",
volname => 'import/import.ova/OS disk.vmdk',
expected =>
['import', 'import.ova/OS disk.vmdk', undef, undef, undef, undef, 'ova+vmdk'],
},
{
- description => "Import, innner file of ova",
+ description => "Import, inner file of ova",
volname => 'import/import.ova/disk.raw',
expected => ['import', 'import.ova/disk.raw', undef, undef, undef, undef, 'ova+raw'],
},
@@ -214,7 +213,7 @@ my $tests = [

# create more test cases for VM disk images matches
my $disk_suffix = ['raw', 'qcow2', 'vmdk'];
-foreach my $s (@$disk_suffix) {
+for my $s ($disk_suffix->@*) {
my @arr = (
{
description => "VM disk image, $s",
@@ -245,7 +244,7 @@ foreach my $s (@$disk_suffix) {
},
);

- push @$tests, @arr;
+ push($tests->@*, @arr);
}

# create more test cases for backup files matches
@@ -255,9 +254,9 @@ my $bkp_suffix = {
openvz => ['tar', 'tgz', 'tar.gz', 'tar.lzo', 'tar.zst'],
};

-foreach my $virt (keys %$bkp_suffix) {
+for my $virt (keys $bkp_suffix->%*) {
my $suffix = $bkp_suffix->{$virt};
- foreach my $s (@$suffix) {
+ for my $s ($suffix->@*) {
my @arr = (
{
description => "Backup archive, $virt, $s",
@@ -274,7 +273,7 @@ foreach my $virt (keys %$bkp_suffix) {
},
);

- push @$tests, @arr;
+ push($tests->@*, @arr);
}
}

@@ -283,9 +282,9 @@ my $non_bkp_suffix = {
qemu => ['vms.gz', 'vma.xz'],
lxc => ['zip.gz', 'tgz.lzo'],
};
-foreach my $virt (keys %$non_bkp_suffix) {
+for my $virt (keys $non_bkp_suffix->%*) {
my $suffix = $non_bkp_suffix->{$virt};
- foreach my $s (@$suffix) {
+ for my $s ($suffix->@*) {
my @arr = (
{
description => "Failed match: Backup archive, $virt, $s",
@@ -295,39 +294,47 @@ foreach my $virt (keys %$non_bkp_suffix) {
},
);

- push @$tests, @arr;
+ push($tests->@*, @arr);
}
}

-#
-# run through test case array
-#
-plan tests => scalar @$tests + 1;
+my sub run_tests($tests) {
+ my $seen_vtype = {};
+ my $vtype_subdirs = { map { $_ => 1 } keys plugin_get_default_vtype_subdirs()->%* };

-my $seen_vtype;
-my $vtype_subdirs =
- { map { $_ => 1 } keys %{ plugin_get_default_vtype_subdirs() } };
+ for my $t ($tests->@*) {
+ my $description = $t->{description};
+ my $volname = $t->{volname};
+ my $expected = $t->{expected};

-foreach my $t (@$tests) {
- my $description = $t->{description};
- my $volname = $t->{volname};
- my $expected = $t->{expected};
+ my $got;
+ eval { $got = [PVE::Storage::Plugin->parse_volname($volname)] };
+ $got = $@ if $@;

- my $got;
- eval { $got = [PVE::Storage::Plugin->parse_volname($volname)] };
- $got = $@ if $@;
+ is_deeply($got, $expected, $description);

- is_deeply($got, $expected, $description);
+ $seen_vtype->{ $expected->[0] } = 1 if ref $expected eq 'ARRAY';
+ }

- $seen_vtype->{ @$expected[0] } = 1 if ref $expected eq 'ARRAY';
+ # to check if all $vtype_subdirs are defined in path_to_volume_id
+ # or have a test
+ # FIXME re-enable after vtype split changes
+ #is_deeply($seen_vtype, $vtype_subdirs, "vtype_subdir check");
+ is_deeply({}, {}, "vtype_subdir check");
+
+ return;
}

-# to check if all $vtype_subdirs are defined in path_to_volume_id
-# or have a test
-# FIXME re-enable after vtype split changes
-#is_deeply($seen_vtype, $vtype_subdirs, "vtype_subdir check");
-is_deeply({}, {}, "vtype_subdir check");
+my sub main() {
+ plan tests => scalar($tests->@*) + 1;

-done_testing();
+ run_tests($tests);
+
+ done_testing();
+
+ return;
+}
+
+main();

1;
--
2.47.3