]>
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, future millenium',
23 archive
=> "backup/vzdump-lxc-$vmid-3070_01_01-00_00_00.tgz",
25 'filename' => "vzdump-lxc-$vmid-3070_01_01-00_00_00.tgz",
26 'logfilename' => "vzdump-lxc-$vmid-3070_01_01-00_00_00.log",
29 'decompressor' => ['tar', '-z'],
30 'compression' => 'gz',
32 'ctime' => 60*60*24 * (365*1100 + 267),
37 description
=> 'Backup archive, lxc, tgz, very old',
38 archive
=> "backup/vzdump-lxc-$vmid-1970_01_01-02_00_30.tgz",
40 'filename' => "vzdump-lxc-$vmid-1970_01_01-02_00_30.tgz",
41 'logfilename' => "vzdump-lxc-$vmid-1970_01_01-02_00_30.log",
44 'decompressor' => ['tar', '-z'],
45 'compression' => 'gz',
47 'ctime' => 60*60*2 + 30,
52 description
=> 'Backup archive, lxc, tgz',
53 archive
=> "backup/vzdump-lxc-$vmid-2020_03_30-21_39_30.tgz",
55 'filename' => "vzdump-lxc-$vmid-2020_03_30-21_39_30.tgz",
56 'logfilename' => "vzdump-lxc-$vmid-2020_03_30-21_39_30.log",
59 'decompressor' => ['tar', '-z'],
60 'compression' => 'gz',
62 'ctime' => 1585604370,
67 description
=> 'Backup archive, openvz, tgz',
68 archive
=> "backup/vzdump-openvz-$vmid-2020_03_30-21_39_30.tgz",
70 'filename' => "vzdump-openvz-$vmid-2020_03_30-21_39_30.tgz",
71 'logfilename' => "vzdump-openvz-$vmid-2020_03_30-21_39_30.log",
74 'decompressor' => ['tar', '-z'],
75 'compression' => 'gz',
77 'ctime' => 1585604370,
82 description
=> 'Backup archive, custom dump directory, qemu, tgz',
83 archive
=> "/here/be/Back-ups/vzdump-qemu-$vmid-2020_03_30-21_39_30.tgz",
85 'filename' => "vzdump-qemu-$vmid-2020_03_30-21_39_30.tgz",
86 'logfilename' => "vzdump-qemu-$vmid-2020_03_30-21_39_30.log",
89 'decompressor' => ['tar', '-z'],
90 'compression' => 'gz',
92 'ctime' => 1585604370,
97 description
=> 'Backup archive, none, tgz',
98 archive
=> "backup/vzdump-qemu-$vmid-whatever-the-name_is_here.tgz",
100 'filename' => "vzdump-qemu-$vmid-whatever-the-name_is_here.tgz",
103 'decompressor' => ['tar', '-z'],
104 'compression' => 'gz',
110 # add new compression fromats to test
114 lzo
=> ['tar', '--lzop'],
115 zst
=> ['tar', '--zstd'],
119 lzo
=> ['lzop', '-d', '-c'],
120 zst
=> ['zstd', '-q', '-d', '-c'],
125 qemu
=> [ 'vma', $decompressor->{vma
}, ],
126 lxc
=> [ 'tar', $decompressor->{tar
}, ],
127 openvz
=> [ 'tar', $decompressor->{tar
}, ],
130 # create more test cases for backup files matches
131 for my $virt (sort keys %$bkp_suffix) {
132 my ($format, $decomp) = $bkp_suffix->{$virt}->@*;
134 for my $suffix (sort keys %$decomp) {
136 description
=> "Backup archive, $virt, $format.$suffix",
137 archive
=> "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$format.$suffix",
139 'filename' => "vzdump-$virt-$vmid-2020_03_30-21_12_40.$format.$suffix",
140 'logfilename' => "vzdump-$virt-$vmid-2020_03_30-21_12_40.log",
142 'format' => "$format",
143 'decompressor' => $decomp->{$suffix},
144 'compression' => "$suffix",
146 'ctime' => 1585602760,
154 # add compression formats to test failed matches
155 my $non_bkp_suffix = {
156 'openvz' => [ 'zip', 'tgz.lzo', 'tar.bz2', 'zip.gz', '', ],
157 'lxc' => [ 'zip', 'tgz.lzo', 'tar.bz2', 'zip.gz', '', ],
158 'qemu' => [ 'vma.xz', 'vms.gz', 'vmx.zst', '', ],
159 'none' => [ 'tar.gz', ],
162 # create tests for failed matches
163 for my $virt (sort keys %$non_bkp_suffix) {
164 my $suffix = $non_bkp_suffix->{$virt};
165 for my $s (@$suffix) {
166 my $archive = "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$s";
168 description
=> "Failed match: Backup archive, $virt, $s",
170 expected
=> "ERROR: couldn't determine archive info from '$archive'\n",
176 plan tests
=> scalar @$tests;
178 for my $tt (@$tests) {
180 my $got = eval { PVE
::Storage
::archive_info
($tt->{archive
}) };
183 is_deeply
($got, $tt->{expected
}, $tt->{description
}) || diag
(explain
($got));