]> git.proxmox.com Git - pve-storage.git/commitdiff
test: filesystem_path
authorAlwin Antreich <a.antreich@proxmox.com>
Tue, 28 Apr 2020 13:58:25 +0000 (15:58 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Thu, 30 Apr 2020 16:37:19 +0000 (18:37 +0200)
Signed-off-by: Alwin Antreich <a.antreich@proxmox.com>
test/filesystem_path_test.pm [new file with mode: 0644]
test/run_plugin_tests.pl

diff --git a/test/filesystem_path_test.pm b/test/filesystem_path_test.pm
new file mode 100644 (file)
index 0000000..c1b6d90
--- /dev/null
@@ -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;
index 9e427eb18bd6ff67fbc436e0e9703f899c029226..e29fc881eccf58de454338d71a923a55e44fcbe2 100755 (executable)
@@ -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};