test: filesystem_path
Signed-off-by: Alwin Antreich <a.antreich@proxmox.com>
This commit is contained in:
committed by
Fabian Grünbichler
parent
ddd313c95e
commit
2eb7ba261d
91
test/filesystem_path_test.pm
Normal file
91
test/filesystem_path_test.pm
Normal 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;
|
||||||
@ -12,6 +12,7 @@ my $res = $harness->runtests(
|
|||||||
"list_volumes_test.pm",
|
"list_volumes_test.pm",
|
||||||
"path_to_volume_id_test.pm",
|
"path_to_volume_id_test.pm",
|
||||||
"get_subdir_test.pm",
|
"get_subdir_test.pm",
|
||||||
|
"filesystem_path_test.pm",
|
||||||
);
|
);
|
||||||
|
|
||||||
exit -1 if !$res || $res->{failed} || $res->{parse_errors};
|
exit -1 if !$res || $res->{failed} || $res->{parse_errors};
|
||||||
|
|||||||
Reference in New Issue
Block a user