]>
git.proxmox.com Git - pve-storage.git/blob - test/archive_info_test.pm
1 package PVE
::Storage
::TestArchiveInfo
;
13 # an array of test cases, each test is comprised of the following keys:
14 # description => to identify a single test
15 # archive => the input filename for archive_info
16 # expected => the hash that archive_info returns
18 # most of them are created further below
22 description
=> 'Backup archive, lxc, tgz',
23 archive
=> "backup/vzdump-lxc-$vmid-2020_03_30-21_39_30.tgz",
25 'filename' => "vzdump-lxc-$vmid-2020_03_30-21_39_30.tgz",
26 'logfilename' => "vzdump-lxc-$vmid-2020_03_30-21_39_30.log",
29 'decompressor' => ['tar', '-z'],
30 'compression' => 'gz',
32 'ctime' => 1585604370,
37 description
=> 'Backup archive, openvz, tgz',
38 archive
=> "backup/vzdump-openvz-$vmid-2020_03_30-21_39_30.tgz",
40 'filename' => "vzdump-openvz-$vmid-2020_03_30-21_39_30.tgz",
41 'logfilename' => "vzdump-openvz-$vmid-2020_03_30-21_39_30.log",
44 'decompressor' => ['tar', '-z'],
45 'compression' => 'gz',
47 'ctime' => 1585604370,
52 description
=> 'Backup archive, custom dump directory, qemu, tgz',
53 archive
=> "/here/be/Back-ups/vzdump-qemu-$vmid-2020_03_30-21_39_30.tgz",
55 'filename' => "vzdump-qemu-$vmid-2020_03_30-21_39_30.tgz",
56 'logfilename' => "vzdump-qemu-$vmid-2020_03_30-21_39_30.log",
59 'decompressor' => ['tar', '-z'],
60 'compression' => 'gz',
62 'ctime' => 1585604370,
67 description
=> 'Backup archive, none, tgz',
68 archive
=> "backup/vzdump-qemu-$vmid-whatever-the-name_is_here.tgz",
70 'filename' => "vzdump-qemu-$vmid-whatever-the-name_is_here.tgz",
73 'decompressor' => ['tar', '-z'],
74 'compression' => 'gz',
80 # add new compression fromats to test
84 lzo
=> ['tar', '--lzop'],
85 zst
=> ['tar', '--zstd'],
89 lzo
=> ['lzop', '-d', '-c'],
90 zst
=> ['zstd', '-q', '-d', '-c'],
95 qemu
=> [ 'vma', $decompressor->{vma
}, ],
96 lxc
=> [ 'tar', $decompressor->{tar
}, ],
97 openvz
=> [ 'tar', $decompressor->{tar
}, ],
100 # create more test cases for backup files matches
101 for my $virt (sort keys %$bkp_suffix) {
102 my ($format, $decomp) = $bkp_suffix->{$virt}->@*;
104 for my $suffix (sort keys %$decomp) {
106 description
=> "Backup archive, $virt, $format.$suffix",
107 archive
=> "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$format.$suffix",
109 'filename' => "vzdump-$virt-$vmid-2020_03_30-21_12_40.$format.$suffix",
110 'logfilename' => "vzdump-$virt-$vmid-2020_03_30-21_12_40.log",
112 'format' => "$format",
113 'decompressor' => $decomp->{$suffix},
114 'compression' => "$suffix",
116 'ctime' => 1585602760,
124 # add compression formats to test failed matches
125 my $non_bkp_suffix = {
126 'openvz' => [ 'zip', 'tgz.lzo', 'tar.bz2', 'zip.gz', '', ],
127 'lxc' => [ 'zip', 'tgz.lzo', 'tar.bz2', 'zip.gz', '', ],
128 'qemu' => [ 'vma.xz', 'vms.gz', 'vmx.zst', '', ],
129 'none' => [ 'tar.gz', ],
132 # create tests for failed matches
133 for my $virt (sort keys %$non_bkp_suffix) {
134 my $suffix = $non_bkp_suffix->{$virt};
135 for my $s (@$suffix) {
136 my $archive = "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$s";
138 description
=> "Failed match: Backup archive, $virt, $s",
140 expected
=> "ERROR: couldn't determine archive info from '$archive'\n",
146 plan tests
=> scalar @$tests;
148 for my $tt (@$tests) {
150 my $got = eval { PVE
::Storage
::archive_info
($tt->{archive
}) };
153 is_deeply
($got, $tt->{expected
}, $tt->{description
}) || diag
(explain
($got));