]> git.proxmox.com Git - pve-storage.git/blob - test/archive_info_test.pm
tests: re-add virt "none" negative test
[pve-storage.git] / test / archive_info_test.pm
1 package PVE::Storage::TestArchiveInfo;
2
3 use strict;
4 use warnings;
5
6 use lib qw(..);
7
8 use PVE::Storage;
9 use Test::More;
10
11 my $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
19 my $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 description => 'Backup archive, none, tgz',
43 archive => "backup/vzdump-qemu-$vmid-whatever-the-name_is_here.tgz",
44 expected => {
45 'type' => 'qemu',
46 'format' => 'tar',
47 'decompressor' => ['tar', '-z'],
48 'compression' => 'gz',
49 },
50 },
51 ];
52
53 # add new compression fromats to test
54 my $decompressor = {
55 tar => {
56 gz => ['tar', '-z'],
57 lzo => ['tar', '--lzop'],
58 zst => ['tar', '--zstd'],
59 },
60 vma => {
61 gz => ['zcat'],
62 lzo => ['lzop', '-d', '-c'],
63 zst => ['zstd', '-q', '-d', '-c'],
64 },
65 };
66
67 my $bkp_suffix = {
68 qemu => [ 'vma', $decompressor->{vma}, ],
69 lxc => [ 'tar', $decompressor->{tar}, ],
70 openvz => [ 'tar', $decompressor->{tar}, ],
71 };
72
73 # create more test cases for backup files matches
74 for my $virt (sort keys %$bkp_suffix) {
75 my ($format, $decomp) = $bkp_suffix->{$virt}->@*;
76
77 for my $suffix (sort keys %$decomp) {
78 push @$tests, {
79 description => "Backup archive, $virt, $format.$suffix",
80 archive => "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$format.$suffix",
81 expected => {
82 'type' => "$virt",
83 'format' => "$format",
84 'decompressor' => $decomp->{$suffix},
85 'compression' => "$suffix",
86 },
87 };
88 }
89 }
90
91
92 # add compression formats to test failed matches
93 my $non_bkp_suffix = {
94 'openvz' => [ 'zip', 'tgz.lzo', 'tar.bz2', 'zip.gz', '', ],
95 'lxc' => [ 'zip', 'tgz.lzo', 'tar.bz2', 'zip.gz', '', ],
96 'qemu' => [ 'vma.xz', 'vms.gz', 'vmx.zst', '', ],
97 'none' => [ 'tar.gz', ],
98 };
99
100 # create tests for failed matches
101 for my $virt (sort keys %$non_bkp_suffix) {
102 my $suffix = $non_bkp_suffix->{$virt};
103 for my $s (@$suffix) {
104 my $archive = "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$s";
105 push @$tests, {
106 description => "Failed match: Backup archive, $virt, $s",
107 archive => $archive,
108 expected => "ERROR: couldn't determine archive info from '$archive'\n",
109 };
110 }
111 }
112
113
114 plan tests => scalar @$tests;
115
116 for my $tt (@$tests) {
117
118 my $got = eval { PVE::Storage::archive_info($tt->{archive}) };
119 $got = $@ if $@;
120
121 is_deeply($got, $tt->{expected}, $tt->{description}) || diag(explain($got));
122 }
123
124 done_testing();
125
126 1;