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 F2AE51FF13B for ; Wed, 22 Apr 2026 13:20:14 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 060B71A684; Wed, 22 Apr 2026 13:15:43 +0200 (CEST) From: "Max R. Carrara" To: pve-devel@lists.proxmox.com Subject: [PATCH pve-storage v1 47/54] test: filesystem path: modernize code Date: Wed, 22 Apr 2026 13:13:13 +0200 Message-ID: <20260422111322.257380-48-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: 1776856366281 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: R6NZRPBPCHGSZRYWCVRVFNG52LIYVUW5 X-Message-ID-Hash: R6NZRPBPCHGSZRYWCVRVFNG52LIYVUW5 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 `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 --- 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