]> git.proxmox.com Git - pve-storage.git/blob - test/filesystem_path_test.pm
rbd plugin: free image: use actual command in error message
[pve-storage.git] / test / filesystem_path_test.pm
1 package PVE::Storage::TestFilesystemPath;
2
3 use strict;
4 use warnings;
5
6 use lib qw(..);
7
8 use PVE::Storage;
9 use Test::More;
10
11 my $path = '/some/path';
12
13 # each array entry is a test that consists of the following keys:
14 # volname => image name that is passed to parse_volname
15 # snapname => to test the die condition
16 # expected => the array of return values; or the die message
17 my $tests = [
18 {
19 volname => '1234/vm-1234-disk-0.raw',
20 snapname => undef,
21 expected => [
22 "$path/images/1234/vm-1234-disk-0.raw",
23 '1234',
24 'images'
25 ],
26 },
27 {
28 volname => '1234/vm-1234-disk-0.raw',
29 snapname => 'my_snap',
30 expected => "can't snapshot this image format\n"
31 },
32 {
33 volname => '1234/vm-1234-disk-0.qcow2',
34 snapname => undef,
35 expected => [
36 "$path/images/1234/vm-1234-disk-0.qcow2",
37 '1234',
38 'images'
39 ],
40 },
41 {
42 volname => '1234/vm-1234-disk-0.qcow2',
43 snapname => 'my_snap',
44 expected => [
45 "$path/images/1234/vm-1234-disk-0.qcow2",
46 '1234',
47 'images'
48 ],
49 },
50 {
51 volname => 'iso/my-awesome-proxmox.iso',
52 snapname => undef,
53 expected => [
54 "$path/template/iso/my-awesome-proxmox.iso",
55 undef,
56 'iso'
57 ],
58 },
59 {
60 volname => "backup/vzdump-qemu-1234-2020_03_30-21_12_40.vma",
61 snapname => undef,
62 expected => [
63 "$path/dump/vzdump-qemu-1234-2020_03_30-21_12_40.vma",
64 1234,
65 'backup'
66 ],
67 },
68 ];
69
70 plan tests => scalar @$tests;
71
72 foreach my $tt (@$tests) {
73 my $volname = $tt->{volname};
74 my $snapname = $tt->{snapname};
75 my $expected = $tt->{expected};
76 my $scfg = { path => $path };
77 my $got;
78
79 eval {
80 $got = [ PVE::Storage::Plugin->filesystem_path($scfg, $volname, $snapname) ];
81 };
82 $got = $@ if $@;
83
84 is_deeply($got, $expected, "wantarray: filesystem_path for $volname")
85 || diag(explain($got));
86
87 }
88
89 done_testing();
90
91 1;