[pve-devel] [PATCH v6 manager 2/2] vzdump: test: adapt and add more tests that are possible now

Aaron Lauterer a.lauterer at proxmox.com
Wed Jun 17 14:13:39 CEST 2020


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.lauterer at proxmox.com>
---

v5 -> v6: adapt call to PVE::VZDump::get_included_guests()

 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 33748513..a0f40a55 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;
@@ -87,84 +87,82 @@ my $addtest = sub {
     };
 };
 
-# is handled in the PVE::VZDump->exec_backup() method for now
-# $addtest->('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
-# $addtest->('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
-# $addtest->('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
-
-$addtest->('Test pool members', {
-    expected_vmids => [ 100, 101 ],
-    expected_skiplist => [ 200, 201 ],
+$addtest->('Test all guests', {
+    expected => {
+	node1 => [ 100, 101, 112, 113 ],
+	node2 => [ 200, 201, 212, 213 ],
+    },
     param => {
-	pool => 'testpool',
+	all => 1,
     }
 });
 
-$addtest->('Test pool members with cluster node limit', {
-    expected_vmids => [ 100, 101, 200, 201 ],
-    expected_skiplist => [],
+$addtest->('Test all guests with node limit', {
+    expected => {
+	node2 => [ 200, 201, 212, 213 ],
+    },
     param => {
-	pool => 'testpool',
+	all => 1,
 	node => 'node2',
     }
 });
 
-$addtest->('Test pool members with local node limit', {
-    expected_vmids => [ 100, 101 ],
-    expected_skiplist => [ 200, 201 ],
+$addtest->('Test exclude', {
+    expected => {
+	node1 =>[ 101, 112, 113 ],
+	node2 => [ 201, 212,  213 ],
+    },
     param => {
-	pool => 'testpool',
+	all => 1,
+	exclude => '100, 102, 200, 202',
+    }
+});
+
+$addtest->('Test exclude with node limit', {
+    expected => {
+	node1 =>[ 101, 112, 113 ],
+    },
+    param => {
+	all => 1,
+	exclude => '100, 102, 200, 202',
 	node => 'node1',
     }
 });
 
-$addtest->('Test selected VMIDs', {
-    expected_vmids => [ 100 ],
-    expected_skiplist => [ 201, 212 ],
+$addtest->('Test pool members', {
+    expected => {
+	node1 =>[ 100, 101 ],
+	node2 => [ 200, 201 ],
+    },
     param => {
-	vmid => '100, 201, 212',
+	pool => 'testpool',
     }
 });
 
+$addtest->('Test pool members with node limit', {
+    expected => {
+	node2 => [ 200, 201 ],
+    },
+    param => {
+	pool => 'testpool',
+	node => 'node2',
+    }
+});
 
-$addtest->('Test selected VMIDs with cluster node limit', {
-    expected_vmids => [ 100, 201, 212 ],
-    expected_skiplist => [],
+$addtest->('Test selected VMIDs', {
+    expected => {
+	node1 =>[ 100 ],
+	node2 => [ 201, 212 ],
+    },
     param => {
 	vmid => '100, 201, 212',
-	node => 'node2',
     }
 });
 
-$addtest->('Test selected VMIDs with local node limit', {
-    expected_vmids => [ 100 ],
-    expected_skiplist => [ 201, 212 ],
+$addtest->('Test selected VMIDs with node limit', {
+    expected => {
+	node1 =>[ 100 ],
+    },
     param => {
 	vmid => '100, 201, 212',
 	node => 'node1',
@@ -172,8 +170,8 @@ $addtest->('Test selected VMIDs with local node limit', {
 });
 
 $addtest->('Test selected VMIDs on other nodes', {
-    expected_vmids => [],
-    expected_skiplist => [ 201, 212 ],
+    expected => {
+    },
     param => {
 	vmid => '201, 212',
 	node => 'node1',
@@ -185,16 +183,11 @@ for my $test (@{$tests}) {
     my $testname = $test->{name};
     my $testdata = $test->{test};
 
-    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





More information about the pve-devel mailing list