From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 025141FF13B for ; Wed, 22 Apr 2026 13:19:26 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 374FF19EC7; Wed, 22 Apr 2026 13:15:06 +0200 (CEST) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage v1 40/54] test: parse volname: modernize code Date: Wed, 22 Apr 2026 13:13:06 +0200 Message-ID: <20260422111322.257380-41-m.carrara@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260422111322.257380-1-m.carrara@proxmox.com> References: <20260422111322.257380-1-m.carrara@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1776856358612 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.083 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: M7HHIAECPD3SM3LFX7MB2V4UGPP5OUML X-Message-ID-Hash: M7HHIAECPD3SM3LFX7MB2V4UGPP5OUML X-MailFrom: m.carrara@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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