]> git.proxmox.com Git - pve-storage.git/blame - test/archive_info_test.pm
archive info: keep some basic strictness
[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 },
4b26f814
AA
41 {
42 description => 'Backup archive, none, tgz',
5029f978 43 archive => "backup/vzdump-qemu-$vmid-whatever-the-name_is_here.tgz",
4b26f814 44 expected => {
5029f978 45 'type' => 'qemu',
4b26f814
AA
46 'format' => 'tar',
47 'decompressor' => ['tar', '-z'],
48 'compression' => 'gz',
49 },
50 },
cd554b79
AA
51];
52
53# add new compression fromats to test
54my $decompressor = {
55 tar => {
56 gz => ['tar', '-z'],
57 lzo => ['tar', '--lzop'],
014d36db 58 zst => ['tar', '--zstd'],
cd554b79
AA
59 },
60 vma => {
61 gz => ['zcat'],
62 lzo => ['lzop', '-d', '-c'],
014d36db 63 zst => ['zstd', '-q', '-d', '-c'],
cd554b79
AA
64 },
65};
66
67my $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
5df46bf2
TL
74for my $virt (sort keys %$bkp_suffix) {
75 my ($format, $decomp) = $bkp_suffix->{$virt}->@*;
cd554b79 76
5df46bf2 77 for my $suffix (sort keys %$decomp) {
c265d421
TL
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",
cd554b79 86 },
c265d421 87 };
cd554b79
AA
88 }
89}
90
91
92# add compression formats to test failed matches
93my $non_bkp_suffix = {
94 'openvz' => [ 'zip', 'tgz.lzo', 'tar.bz2', 'zip.gz', '', ],
95 'lxc' => [ 'zip', 'tgz.lzo', 'tar.bz2', 'zip.gz', '', ],
014d36db 96 'qemu' => [ 'vma.xz', 'vms.gz', 'vmx.zst', '', ],
cd554b79
AA
97};
98
99# create tests for failed matches
5df46bf2 100for my $virt (sort keys %$non_bkp_suffix) {
cd554b79 101 my $suffix = $non_bkp_suffix->{$virt};
c265d421 102 for my $s (@$suffix) {
bf5af0fb 103 my $archive = "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$s";
c265d421
TL
104 push @$tests, {
105 description => "Failed match: Backup archive, $virt, $s",
bf5af0fb
TL
106 archive => $archive,
107 expected => "ERROR: couldn't determine archive info from '$archive'\n",
c265d421 108 };
cd554b79
AA
109 }
110}
111
112
113plan tests => scalar @$tests;
114
3dde6a9c
TL
115for my $tt (@$tests) {
116
117 my $got = eval { PVE::Storage::archive_info($tt->{archive}) };
cd554b79
AA
118 $got = $@ if $@;
119
3dde6a9c 120 is_deeply($got, $tt->{expected}, $tt->{description}) || diag(explain($got));
cd554b79
AA
121}
122
123done_testing();
124
1251;