]>
git.proxmox.com Git - pve-storage.git/blob - test/archive_info_test.pm
5e5ca8a93512b72ea5eecaa79bdf61656a3b18de
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",
27 'decompressor' => ['tar', '-z'],
28 'compression' => 'gz',
30 'ctime' => 1585604370,
35 description
=> 'Backup archive, openvz, tgz',
36 archive
=> "backup/vzdump-openvz-$vmid-2020_03_30-21_39_30.tgz",
40 'decompressor' => ['tar', '-z'],
41 'compression' => 'gz',
43 'ctime' => 1585604370,
48 description
=> 'Backup archive, none, tgz',
49 archive
=> "backup/vzdump-qemu-$vmid-whatever-the-name_is_here.tgz",
53 'decompressor' => ['tar', '-z'],
54 'compression' => 'gz',
60 # add new compression fromats to test
64 lzo
=> ['tar', '--lzop'],
65 zst
=> ['tar', '--zstd'],
69 lzo
=> ['lzop', '-d', '-c'],
70 zst
=> ['zstd', '-q', '-d', '-c'],
75 qemu
=> [ 'vma', $decompressor->{vma
}, ],
76 lxc
=> [ 'tar', $decompressor->{tar
}, ],
77 openvz
=> [ 'tar', $decompressor->{tar
}, ],
80 # create more test cases for backup files matches
81 for my $virt (sort keys %$bkp_suffix) {
82 my ($format, $decomp) = $bkp_suffix->{$virt}->@*;
84 for my $suffix (sort keys %$decomp) {
86 description
=> "Backup archive, $virt, $format.$suffix",
87 archive
=> "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$format.$suffix",
90 'format' => "$format",
91 'decompressor' => $decomp->{$suffix},
92 'compression' => "$suffix",
94 'ctime' => 1585602760,
102 # add compression formats to test failed matches
103 my $non_bkp_suffix = {
104 'openvz' => [ 'zip', 'tgz.lzo', 'tar.bz2', 'zip.gz', '', ],
105 'lxc' => [ 'zip', 'tgz.lzo', 'tar.bz2', 'zip.gz', '', ],
106 'qemu' => [ 'vma.xz', 'vms.gz', 'vmx.zst', '', ],
107 'none' => [ 'tar.gz', ],
110 # create tests for failed matches
111 for my $virt (sort keys %$non_bkp_suffix) {
112 my $suffix = $non_bkp_suffix->{$virt};
113 for my $s (@$suffix) {
114 my $archive = "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$s";
116 description
=> "Failed match: Backup archive, $virt, $s",
118 expected
=> "ERROR: couldn't determine archive info from '$archive'\n",
124 plan tests
=> scalar @$tests;
126 for my $tt (@$tests) {
128 my $got = eval { PVE
::Storage
::archive_info
($tt->{archive
}) };
131 is_deeply
($got, $tt->{expected
}, $tt->{description
}) || diag
(explain
($got));