Now, with the logic for `all` and `exclude` in the same single method, additional tests for these cases are possible.
Adapt to hash return value of `get_included_guests`. Signed-off-by: Aaron Lauterer <a.laute...@proxmox.com> --- test/vzdump_guest_included_test.pl | 123 ++++++++++++++--------------- 1 file changed, 58 insertions(+), 65 deletions(-) diff --git a/test/vzdump_guest_included_test.pl b/test/vzdump_guest_included_test.pl index 378ad474..8b6db561 100755 --- a/test/vzdump_guest_included_test.pl +++ b/test/vzdump_guest_included_test.pl @@ -9,7 +9,7 @@ use warnings; use lib '..'; -use Test::More tests => 7; +use Test::More tests => 9; use Test::MockModule; use PVE::VZDump; @@ -78,84 +78,82 @@ $pve_api2tools->mock( my $tests = {}; -# is handled in the PVE::VZDump->exec_backup() method for now -# $tests->{'Test all guests'} = { -# expected_vmids => [ 100, 101, 112, 113, 200, 201, 212, 213 ], -# expected_skiplist => [ ], -# param => { -# all => 1, -# } -# }; - -# is handled in the PVE::VZDump->exec_backup() method for now -# $tests->{'Test all guests with cluster node limit'} = { -# expected_vmids => [ 100, 101, 112, 113, 200, 201, 212, 213 ], -# expected_skiplist => [], -# param => { -# all => 1, -# node => 'node2', -# } -# }; - -# is handled in the PVE::VZDump->exec_backup() method for now -# $tests->{'Test all guests with local node limit'} = { -# expected_vmids => [ 100, 101, 112, 113 ], -# expected_skiplist => [ 200, 201, 212, 213 ], -# param => { -# all => 1, -# node => 'node1', -# } -# }; -# -# TODO: all test variants with exclude - -$tests->{'Test pool members'} = { - expected_vmids => [ 100, 101 ], - expected_skiplist => [ 200, 201 ], +$tests->{'Test all guests'} = { + expected => { + node1 => [ 100, 101, 112, 113 ], + node2 => [ 200, 201, 212, 213 ], + }, param => { - pool => 'testpool', + all => 1, } }; -$tests->{'Test pool members with cluster node limit'} = { - expected_vmids => [ 100, 101, 200, 201 ], - expected_skiplist => [], +$tests->{'Test all guests with node limit'} = { + expected => { + node2 => [ 200, 201, 212, 213 ], + }, param => { - pool => 'testpool', + all => 1, node => 'node2', } }; -$tests->{'Test pool members with local node limit'} = { - expected_vmids => [ 100, 101 ], - expected_skiplist => [ 200, 201 ], +$tests->{'Test exclude'} = { + expected => { + node1 =>[ 101, 112, 113 ], + node2 => [ 201, 212, 213 ], + }, param => { - pool => 'testpool', + all => 1, + exclude => '100, 102, 200, 202', + } +}; + +$tests->{'Test exclude with node limit'} = { + expected => { + node1 =>[ 101, 112, 113 ], + }, + param => { + all => 1, + exclude => '100, 102, 200, 202', node => 'node1', } }; -$tests->{'Test selected VMIDs'} = { - expected_vmids => [ 100 ], - expected_skiplist => [ 201, 212 ], +$tests->{'Test pool members'} = { + expected => { + node1 =>[ 100, 101 ], + node2 => [ 200, 201 ], + }, param => { - vmid => '100, 201, 212', + pool => 'testpool', } }; +$tests->{'Test pool members with node limit'} = { + expected => { + node2 => [ 200, 201 ], + }, + param => { + pool => 'testpool', + node => 'node2', + } +}; -$tests->{'Test selected VMIDs with cluster node limit'} = { - expected_vmids => [ 100, 201, 212 ], - expected_skiplist => [], +$tests->{'Test selected VMIDs'} = { + expected => { + node1 =>[ 100 ], + node2 => [ 201, 212 ], + }, param => { vmid => '100, 201, 212', - node => 'node2', } }; -$tests->{'Test selected VMIDs with local node limit'} = { - expected_vmids => [ 100 ], - expected_skiplist => [ 201, 212 ], +$tests->{'Test selected VMIDs with node limit'} = { + expected => { + node1 =>[ 100 ], + }, param => { vmid => '100, 201, 212', node => 'node1', @@ -163,8 +161,8 @@ $tests->{'Test selected VMIDs with local node limit'} = { }; $tests->{'Test selected VMIDs on other nodes'} = { - expected_vmids => [], - expected_skiplist => [ 201, 212 ], + expected => { + }, param => { vmid => '201, 212', node => 'node1', @@ -176,16 +174,11 @@ $tests->{'Test selected VMIDs on other nodes'} = { foreach my $testname (sort keys %{$tests}) { my $testdata = $tests->{$testname}; - note($testname); - my $expected = [ $testdata->{expected_vmids}, $testdata->{expected_skiplist} ]; - - my ($local, $cluster) = PVE::VZDump->get_included_guests($testdata->{param}); - my $result = [ $local, $cluster ]; + # note($testname); - # print "Expected: " . Dumper($expected); - # print "Returned: " . Dumper($result); + my $result = PVE::VZDump->get_included_guests($testdata->{param}); - is_deeply($result, $expected, $testname); + is_deeply($result, $testdata->{expected}, $testname); } exit(0); -- 2.20.1 _______________________________________________ pve-devel mailing list pve-devel@pve.proxmox.com https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel