]> git.proxmox.com Git - pve-storage.git/blobdiff - test/archive_info_test.pm
Extend archive_info to include filename and logfilename
[pve-storage.git] / test / archive_info_test.pm
index 283fe47a266df97b49668c4196fa19e92149292a..2f9811c1f9fcd54637014fe42cc6ac3eb0428053 100644 (file)
@@ -22,20 +22,57 @@ my $tests = [
        description => 'Backup archive, lxc, tgz',
        archive     => "backup/vzdump-lxc-$vmid-2020_03_30-21_39_30.tgz",
        expected    => {
+           'filename'     => "vzdump-lxc-$vmid-2020_03_30-21_39_30.tgz",
+           'logfilename'  => "vzdump-lxc-$vmid-2020_03_30-21_39_30.log",
            'type'         => 'lxc',
            'format'       => 'tar',
            'decompressor' => ['tar', '-z'],
            'compression'  => 'gz',
+           'vmid'         => $vmid,
+           'ctime'        => 1585604370,
+           'is_std_name'  => 1,
        },
     },
     {
        description => 'Backup archive, openvz, tgz',
        archive     => "backup/vzdump-openvz-$vmid-2020_03_30-21_39_30.tgz",
        expected    => {
+           'filename'     => "vzdump-openvz-$vmid-2020_03_30-21_39_30.tgz",
+           'logfilename'  => "vzdump-openvz-$vmid-2020_03_30-21_39_30.log",
            'type'         => 'openvz',
            'format'       => 'tar',
            'decompressor' => ['tar', '-z'],
            'compression'  => 'gz',
+           'vmid'         => $vmid,
+           'ctime'        => 1585604370,
+           'is_std_name'  => 1,
+       },
+    },
+    {
+       description => 'Backup archive, custom dump directory, qemu, tgz',
+       archive     => "/here/be/Back-ups/vzdump-qemu-$vmid-2020_03_30-21_39_30.tgz",
+       expected    => {
+           'filename'     => "vzdump-qemu-$vmid-2020_03_30-21_39_30.tgz",
+           'logfilename'  => "vzdump-qemu-$vmid-2020_03_30-21_39_30.log",
+           'type'         => 'qemu',
+           'format'       => 'tar',
+           'decompressor' => ['tar', '-z'],
+           'compression'  => 'gz',
+           'vmid'         => $vmid,
+           'ctime'        => 1585604370,
+           'is_std_name'  => 1,
+       },
+    },
+    {
+       description => 'Backup archive, none, tgz',
+       archive     => "backup/vzdump-qemu-$vmid-whatever-the-name_is_here.tgz",
+       expected    => {
+           'filename'     => "vzdump-qemu-$vmid-whatever-the-name_is_here.tgz",
+           'type'         => 'qemu',
+           'format'       => 'tar',
+           'decompressor' => ['tar', '-z'],
+           'compression'  => 'gz',
+           'is_std_name'  => 0,
        },
     },
 ];
@@ -61,24 +98,25 @@ my $bkp_suffix = {
 };
 
 # create more test cases for backup files matches
-foreach my $virt (keys %$bkp_suffix) {
-    my ($format, $decomp) = @{ $bkp_suffix->{$virt} };
-
-    foreach my $suffix (keys %$decomp) {
-       my @arr = (
-           {
-               description => "Backup archive, $virt, $format.$suffix",
-               archive     => "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$format.$suffix",
-               expected    => {
-                   'type'         => "$virt",
-                   'format'       => "$format",
-                   'decompressor' => $decomp->{$suffix},
-                   'compression'  => "$suffix",
-               },
+for my $virt (sort keys %$bkp_suffix) {
+    my ($format, $decomp) = $bkp_suffix->{$virt}->@*;
+
+    for my $suffix (sort keys %$decomp) {
+       push @$tests, {
+           description => "Backup archive, $virt, $format.$suffix",
+           archive     => "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$format.$suffix",
+           expected    => {
+               'filename'     => "vzdump-$virt-$vmid-2020_03_30-21_12_40.$format.$suffix",
+               'logfilename'  => "vzdump-$virt-$vmid-2020_03_30-21_12_40.log",
+               'type'         => "$virt",
+               'format'       => "$format",
+               'decompressor' => $decomp->{$suffix},
+               'compression'  => "$suffix",
+               'vmid'         => $vmid,
+               'ctime'        => 1585602760,
+               'is_std_name'  => 1,
            },
-       );
-
-       push @$tests, @arr;
+       };
     }
 }
 
@@ -92,34 +130,27 @@ my $non_bkp_suffix = {
 };
 
 # create tests for failed matches
-foreach my $virt (keys %$non_bkp_suffix) {
+for my $virt (sort keys %$non_bkp_suffix) {
     my $suffix = $non_bkp_suffix->{$virt};
-    foreach my $s (@$suffix) {
-       my @arr = (
-           {
-               description => "Failed match: Backup archive, $virt, $s",
-               archive     => "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$s",
-               expected    => "ERROR: couldn't determine format and compression type\n",
-           },
-       );
-
-       push @$tests, @arr;
+    for my $s (@$suffix) {
+       my $archive = "backup/vzdump-$virt-$vmid-2020_03_30-21_12_40.$s";
+       push @$tests, {
+           description => "Failed match: Backup archive, $virt, $s",
+           archive     => $archive,
+           expected    => "ERROR: couldn't determine archive info from '$archive'\n",
+       };
     }
 }
 
 
 plan tests => scalar @$tests;
 
-# run through tests array
-foreach my $tt (@$tests) {
-    my $description = $tt->{description};
-    my $archive = $tt->{archive};
-    my $expected = $tt->{expected};
-    my $got;
-    eval { $got = PVE::Storage::archive_info($archive) };
+for my $tt (@$tests) {
+
+    my $got = eval { PVE::Storage::archive_info($tt->{archive}) };
     $got = $@ if $@;
 
-    is_deeply($got, $expected, $description) || diag(explain($got));
+    is_deeply($got, $tt->{expected}, $tt->{description}) || diag(explain($got));
 }
 
 done_testing();