5
0
mirror of git://git.proxmox.com/git/pve-storage.git synced 2025-02-09 09:57:38 +03:00

test: filesystem_path

Signed-off-by: Alwin Antreich <a.antreich@proxmox.com>
This commit is contained in:
Alwin Antreich 2020-04-28 15:58:25 +02:00 committed by Fabian Grünbichler
parent ddd313c95e
commit 2eb7ba261d
2 changed files with 92 additions and 0 deletions

View File

@ -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;

View File

@ -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};