[pve-devel] [PATCH storage v5 12/12] test: filesystem_path

Alwin Antreich a.antreich at proxmox.com
Tue Apr 28 15:58:25 CEST 2020


Signed-off-by: Alwin Antreich <a.antreich at proxmox.com>
---
 test/filesystem_path_test.pm | 91 ++++++++++++++++++++++++++++++++++++
 test/run_plugin_tests.pl     |  1 +
 2 files changed, 92 insertions(+)
 create mode 100644 test/filesystem_path_test.pm

diff --git a/test/filesystem_path_test.pm b/test/filesystem_path_test.pm
new file mode 100644
index 0000000..c1b6d90
--- /dev/null
+++ b/test/filesystem_path_test.pm
@@ -0,0 +1,91 @@
+package PVE::Storage::TestFilesystemPath;
+
+use strict;
+use warnings;
+
+use lib qw(..);
+
+use PVE::Storage;
+use Test::More;
+
+my $path = '/some/path';
+
+# each array entry is a test that consists of the following keys:
+# volname  => image name that is passed to parse_volname
+# snapname => to test the die condition
+# expected => the array of return values; or the die message
+my $tests = [
+    {
+	volname  => '1234/vm-1234-disk-0.raw',
+	snapname => undef,
+	expected => [
+	    "$path/images/1234/vm-1234-disk-0.raw",
+	    '1234',
+	    'images'
+	],
+    },
+    {
+	volname  => '1234/vm-1234-disk-0.raw',
+	snapname => 'my_snap',
+	expected => "can't snapshot this image format\n"
+    },
+    {
+	volname  => '1234/vm-1234-disk-0.qcow2',
+	snapname => undef,
+	expected => [
+	    "$path/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'
+	],
+    },
+    {
+	volname  => 'iso/my-awesome-proxmox.iso',
+	snapname => undef,
+	expected => [
+	    "$path/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'
+	],
+    },
+];
+
+plan tests => scalar @$tests;
+
+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 $@;
+
+    is_deeply($got, $expected, "wantarray: filesystem_path for $volname")
+    || diag(explain($got));
+
+}
+
+done_testing();
+
+1;
diff --git a/test/run_plugin_tests.pl b/test/run_plugin_tests.pl
index 9e427eb..e29fc88 100755
--- a/test/run_plugin_tests.pl
+++ b/test/run_plugin_tests.pl
@@ -12,6 +12,7 @@ my $res = $harness->runtests(
     "list_volumes_test.pm",
     "path_to_volume_id_test.pm",
     "get_subdir_test.pm",
+    "filesystem_path_test.pm",
 );
 
 exit -1 if !$res || $res->{failed} || $res->{parse_errors};
-- 
2.20.1





More information about the pve-devel mailing list