]> git.proxmox.com Git - qemu-server.git/blob - test/run_qemu_restore_config_tests.pl
restore: update config: remove unused parameter
[qemu-server.git] / test / run_qemu_restore_config_tests.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use lib qw(..);
7
8 use Test::More;
9
10 use File::Basename;
11
12 use PVE::QemuServer;
13 use PVE::Tools qw(dir_glob_foreach file_get_contents);
14
15 my $INPUT_DIR = './restore-config-input';
16 my $EXPECTED_DIR = './restore-config-expected';
17
18 # NOTE update when you add/remove tests
19 plan tests => 4;
20
21 dir_glob_foreach('./restore-config-input', '[0-9]+.conf', sub {
22 my ($file) = @_;
23
24 my $vmid = basename($file, ('.conf'));
25
26 my $fh = IO::File->new("${INPUT_DIR}/${file}", "r") or
27 die "unable to read '$file' - $!\n";
28
29 my $map = {};
30 my $disknum = 0;
31
32 # NOTE For now, the map is hardcoded to a file-based 'target' storage.
33 # In the future, the test could be extended to include parse_backup_hints
34 # and restore_allocate_devices. Even better if the config-related logic from
35 # the restore_XYZ_archive functions could become a separate function.
36 while (defined(my $line = <$fh>)) {
37 if ($line =~ m/^\#qmdump\#map:(\S+):(\S+):(\S*):(\S*):$/) {
38 my ($drive, undef, $storeid, $fmt) = ($1, $2, $3, $4);
39
40 $fmt ||= 'raw';
41
42 $map->{$drive} = "target:${vmid}/vm-${vmid}-disk-${disknum}.${fmt}";
43 $disknum++;
44 }
45 }
46
47 $fh->seek(0, 0) or die "seek failed - $!\n";
48
49 my $got = '';
50 my $cookie = { netcount => 0 };
51
52 while (defined(my $line = <$fh>)) {
53 $got .= PVE::QemuServer::restore_update_config_line(
54 $cookie,
55 $map,
56 $line,
57 0,
58 );
59 }
60
61 my $expected = file_get_contents("${EXPECTED_DIR}/${file}");
62
63 is_deeply($got, $expected, $file);
64 });
65
66 done_testing();