[PATCH pve-storage v1 47/54] test: filesystem path: modernize code

Max R. Carrara
2026-04-22T11:20:14Z

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

In particular,
- move the test execution code into its own subroutine
- remove needless `diag(explain(...))` call
- add and call a `main()` subroutine
- declare `use v5.36;` instead of `use strict;` and `use warnings;`
- rename / capitalize the sole constant
- adapt the code style to fit our more modern style guide

Signed-off-by: Max R. Carrara <m.carrara@proxmox.com>
---
src/test/filesystem_path_test.pm | 53 +++++++++++++++++++-------------
1 file changed, 32 insertions(+), 21 deletions(-)

diff --git a/src/test/filesystem_path_test.pm b/src/test/filesystem_path_test.pm
index af52380c..5a715ce9 100644
--- a/src/test/filesystem_path_test.pm
+++ b/src/test/filesystem_path_test.pm
@@ -1,14 +1,14 @@
package PVE::Storage::TestFilesystemPath;

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

use lib qw(..);

use PVE::Storage;
+
use Test::More;

-my $path = '/some/path';
+my $DEFAULT_STORAGE_DIR = '/some/path';

# each array entry is a test that consists of the following keys:
# volname => image name that is passed to parse_volname
@@ -19,7 +19,7 @@ my $tests = [
volname => '1234/vm-1234-disk-0.raw',
snapname => undef,
expected => [
- "$path/images/1234/vm-1234-disk-0.raw", '1234', 'images',
+ "$DEFAULT_STORAGE_DIR/images/1234/vm-1234-disk-0.raw", '1234', 'images',
],
},
{
@@ -31,49 +31,60 @@ my $tests = [
volname => '1234/vm-1234-disk-0.qcow2',
snapname => undef,
expected => [
- "$path/images/1234/vm-1234-disk-0.qcow2", '1234', 'images',
+ "$DEFAULT_STORAGE_DIR/images/1234/vm-1234-disk-0.qcow2", '1234', 'images',
],
},
{
volname => '1234/vm-1234-disk-0.qcow2',
snapname => 'my_snap',
expected => [
- "$path/images/1234/vm-1234-disk-0.qcow2", '1234', 'images',
+ "$DEFAULT_STORAGE_DIR/images/1234/vm-1234-disk-0.qcow2", '1234', 'images',
],
},
{
volname => 'iso/my-awesome-proxmox.iso',
snapname => undef,
expected => [
- "$path/template/iso/my-awesome-proxmox.iso", undef, 'iso',
+ "$DEFAULT_STORAGE_DIR/template/iso/my-awesome-proxmox.iso", undef, 'iso',
],
},
{
volname => "backup/vzdump-qemu-1234-2020_03_30-21_12_40.vma",
snapname => undef,
expected => [
- "$path/dump/vzdump-qemu-1234-2020_03_30-21_12_40.vma", 1234, 'backup',
+ "$DEFAULT_STORAGE_DIR/dump/vzdump-qemu-1234-2020_03_30-21_12_40.vma", 1234,
+ 'backup',
],
},
];

-plan tests => scalar @$tests;
+my sub run_tests($tests) {
+ for my $t ($tests->@*) {
+ my $volname = $t->{volname};
+ my $snapname = $t->{snapname};
+ my $expected = $t->{expected};
+ my $scfg = { path => $DEFAULT_STORAGE_DIR };
+ my $got;

-foreach my $tt (@$tests) {
- my $volname = $tt->{volname};
- my $snapname = $tt->{snapname};
- my $expected = $tt->{expected};
- my $scfg = { path => $path };
- my $got;
+ eval { $got = [PVE::Storage::Plugin->filesystem_path($scfg, $volname, $snapname)]; };
+ $got = $@ if $@;

- eval { $got = [PVE::Storage::Plugin->filesystem_path($scfg, $volname, $snapname)]; };
- $got = $@ if $@;
-
- is_deeply($got, $expected, "wantarray: filesystem_path for $volname")
- || diag(explain($got));
+ is_deeply($got, $expected, "wantarray: filesystem_path for $volname");
+ }

+ return;
}

-done_testing();
+my sub main() {
+ plan tests => scalar($tests->@*);
+
+ run_tests($tests);
+
+ done_testing();
+
+ return;
+}
+
+main();

1;
--
2.47.3