[PATCH pve-storage v1 34/54] test: list volumes: reorganize and modernize test running code

Max R. Carrara
2026-04-22T11:17:09Z

Use the `use v5.36` pragma to enable subroutine signatures,
warnings and strictness by default.

Factor out the list of file suffixes for file formats that support
backing files into its own constant.

Introduce a `main()` subroutine.

Move the code that runs the existing tests for
`::Plugin->list_volumes()` into its own subroutine.

Move the remaining single test that checks whether the vmlist returned
by `PVE::Cluster::get_vmlist()` was modified into `main()`.

Move the call to `Test::More`'s `plan()` into `main()` as well.

Done as a preparational step for other changes.

Signed-off-by: Max R. Carrara <m.carrara@proxmox.com>
---
src/test/list_volumes_test.pm | 66 ++++++++++++++++++++---------------
1 file changed, 38 insertions(+), 28 deletions(-)

diff --git a/src/test/list_volumes_test.pm b/src/test/list_volumes_test.pm
index 5cb08880..053ebbe3 100644
--- a/src/test/list_volumes_test.pm
+++ b/src/test/list_volumes_test.pm
@@ -1,7 +1,6 @@
package PVE::Storage::TestListVolumes;

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

use lib qw(..);

@@ -13,7 +12,7 @@ use Test::More;
use Test::MockModule;

use Cwd;
-use File::Basename;
+use File::Basename qw(fileparse);
use File::Path qw(make_path remove_tree);
use File::stat qw();
use File::Temp;
@@ -76,6 +75,8 @@ my $scfg = {
},
};

+my @BACKING_FILE_SUFFIXES = ('qcow2', 'raw', 'vmdk', 'vhdx');
+
# The test cases are comprised of an arry of hashes with the following keys:
# description => displayed on error by Test::More
# vmid => used for image matches by list_volume
@@ -667,31 +668,9 @@ my sub cmp_volinfo_by_volid {
return $a->{volid} cmp $b->{volid};
}

-my $plan = scalar @tests;
-plan tests => $plan + 1;
-
-{
- # don't accidentally modify vmlist, see bug report
- # https://pve.proxmox.com/pipermail/pve-devel/2020-January/041096.html
- my $scfg_with_type = { path => $storage_dir, type => 'dir' };
- my $original_vmlist = { ids => {} };
- my $tested_vmlist = dclone($original_vmlist);
-
- PVE::Storage::Plugin->list_volumes('sid', $scfg_with_type, undef, ['images']);
-
- is_deeply($tested_vmlist, $original_vmlist, 'PVE::Cluster::vmlist remains unmodified')
- || diag(
- "Expected vmlist to remain\n",
- explain($original_vmlist),
- "but it turned to\n",
- explain($tested_vmlist),
- );
-}
-
-{
+my sub run_legacy_tests() {
my $sid = 'local';
my $types = [grep { $scfg->{content}->{$_} } keys $scfg->{content}->%*];
- my @suffixes = ('qcow2', 'raw', 'vmdk', 'vhdx');

# run through test cases
foreach my $tt (@tests) {
@@ -704,7 +683,7 @@ plan tests => $plan + 1;
# prepare environment
my $num = 0; #parent disks
for my $file (@$files) {
- my ($name, $dir, $suffix) = fileparse($file, @suffixes);
+ my ($name, $dir, $suffix) = fileparse($file, @BACKING_FILE_SUFFIXES);

make_path($dir, { verbose => 1, mode => 0755 });

@@ -732,8 +711,39 @@ plan tests => $plan + 1;
# we get wrong results from leftover files
remove_tree($storage_dir, { verbose => 1 });
}
+
+ return;
}

-done_testing();
+sub main() {
+ my $plan = scalar @tests;
+ plan tests => $plan + 1;
+
+ {
+ # don't accidentally modify vmlist, see bug report
+ # https://pve.proxmox.com/pipermail/pve-devel/2020-January/041096.html
+ my $scfg_with_type = { path => $storage_dir, type => 'dir' };
+ my $original_vmlist = { ids => {} };
+ my $tested_vmlist = dclone($original_vmlist);
+
+ PVE::Storage::Plugin->list_volumes('sid', $scfg_with_type, undef, ['images']);
+
+ is_deeply($tested_vmlist, $original_vmlist, 'PVE::Cluster::vmlist remains unmodified')
+ || diag(
+ "Expected vmlist to remain\n",
+ explain($original_vmlist),
+ "but it turned to\n",
+ explain($tested_vmlist),
+ );
+ }
+
+ run_legacy_tests();
+
+ done_testing();
+
+ return;
+}
+
+main();

1;
--
2.47.3