]> git.proxmox.com Git - pve-storage.git/blame - test/archive_info_test.pm
Fix #2737: Can't call method "mode"
[pve-storage.git] / test / archive_info_test.pm
CommitLineData
cd554b79
AA
1package PVE::Storage::TestArchiveInfo;
2
3use strict;
4use warnings;
5
6use lib qw(..);
7
8use PVE::Storage;
9use Test::More;
10
11my $vmid = 16110;
12
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
17#
18# most of them are created further below
19my $tests = [
20 # backup archives
21 {
22 description => 'Backup archive, lxc, tgz',
23 archive => "backup/vzdump-lxc-$vmid-2020_03_30-21_39_30.tgz",
24 expected => {
25 'type' => 'lxc',
26 'format' => 'tar',
27 'decompressor' => ['tar', '-z'],
28 'compression' => 'gz',
29 },
30 },
31 {
32 description => 'Backup archive, openvz, tgz',
33 archive => "backup/vzdump-openvz-$vmid-2020_03_30-21_39_30.tgz",
34 expected => {
35 'type' => 'openvz',
36 'format' => 'tar',
37 'decompressor' => ['tar', '-z'],
38 'compression' => 'gz',
39 },
40 },
41];
42
43# add new compression fromats to test
44my $decompressor = {
45 tar => {
46 gz => ['tar', '-z'],
47 lzo => ['tar', '--lzop'],
014d36db 48 zst => ['tar', '--zstd'],
cd554b79
AA
49 },
50 vma => {
51 gz => ['zcat'],
52 lzo => ['lzop', '-d', '-c'],
014d36db 53 zst => ['zstd', '-q', '-d', '-c'],
cd554b79
AA
54 },
55};
56
57my $bkp_suffix = {
58 qemu => [ 'vma', $decompressor->{vma}, ],
59 lxc => [ 'tar', $decompressor->{tar}, ],
60 openvz => [ 'tar', $decompressor->{tar}, ],
61};
62
63# create more test cases for backup files matches
64foreach my $virt (keys %$bkp_suffix) {
65 my ($format, $decomp) = @{ $bkp_suffix->{$virt} };
66
67 foreach my $suffix (keys %$decomp) {
68 my @arr = (
69 {
70 description => "Backup archive, $virt, $format.$suffix",
71 archive => "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$format.$suffix",
72 expected => {
73 'type' => "$virt",
74 'format' => "$format",
75 'decompressor' => $decomp->{$suffix},
76 'compression' => "$suffix",
77 },
78 },
79 );
80
81 push @$tests, @arr;
82 }
83}
84
85
86# add compression formats to test failed matches
87my $non_bkp_suffix = {
88 'openvz' => [ 'zip', 'tgz.lzo', 'tar.bz2', 'zip.gz', '', ],
89 'lxc' => [ 'zip', 'tgz.lzo', 'tar.bz2', 'zip.gz', '', ],
014d36db 90 'qemu' => [ 'vma.xz', 'vms.gz', 'vmx.zst', '', ],
cd554b79
AA
91 'none' => [ 'tar.gz', ],
92};
93
94# create tests for failed matches
95foreach my $virt (keys %$non_bkp_suffix) {
96 my $suffix = $non_bkp_suffix->{$virt};
97 foreach my $s (@$suffix) {
98 my @arr = (
99 {
100 description => "Failed match: Backup archive, $virt, $s",
101 archive => "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$s",
102 expected => "ERROR: couldn't determine format and compression type\n",
103 },
104 );
105
106 push @$tests, @arr;
107 }
108}
109
110
111plan tests => scalar @$tests;
112
113# run through tests array
114foreach my $tt (@$tests) {
115 my $description = $tt->{description};
116 my $archive = $tt->{archive};
117 my $expected = $tt->{expected};
118 my $got;
119 eval { $got = PVE::Storage::archive_info($archive) };
120 $got = $@ if $@;
121
122 is_deeply($got, $expected, $description) || diag(explain($got));
123}
124
125done_testing();
126
1271;