extend index reconstruct tests for multivol backups
[python-delta-tar] / testing / test_recover.py
index 6e8ab99..025dd2e 100644 (file)
@@ -305,6 +305,22 @@ class DefectiveTest (BaseTest):
         return bak_path, backup_file, backup_full, index_file
 
 
+    def gen_multivol (self, nvol):
+        # add n files for one nth the volume size each, corrected
+        # for metadata and tar block overhead
+        fsiz = int (  (  TEST_VOLSIZ
+                       / (TEST_FILESPERVOL * VOLUME_OVERHEAD))
+                    * 1024 * 1024)
+        fcnt = (self.VOLUMES - 1) * TEST_FILESPERVOL
+        for i in range (fcnt):
+            nvol, invol = divmod(i, TEST_FILESPERVOL)
+            f = "dummy_vol_%d_n_%0.2d" % (nvol, invol)
+            self.hash [f] = self.create_file ("%s/%s"
+                                              % (self.src_path, f),
+                                              fsiz,
+                                              random=True)
+
+
 class RecoverTest (DefectiveTest):
     """
     Recover: restore corrupt backups from index file information.
@@ -322,19 +338,7 @@ class RecoverTest (DefectiveTest):
             self.gen_file_names (self.COMPRESSION, self.PASSWORD)
 
         if self.VOLUMES > 1:
-            # add n files for one nth the volume size each, corrected
-            # for metadata and tar block overhead
-            fsiz = int (  (  TEST_VOLSIZ
-                           / (TEST_FILESPERVOL * VOLUME_OVERHEAD))
-                        * 1024 * 1024)
-            fcnt = (self.VOLUMES - 1) * TEST_FILESPERVOL
-            for i in range (fcnt):
-                nvol, invol = divmod(i, TEST_FILESPERVOL)
-                f = "dummy_vol_%d_n_%0.2d" % (nvol, invol)
-                self.hash [f] = self.create_file ("%s/%s"
-                                                  % (self.src_path, f),
-                                                  fsiz,
-                                                  random=True)
+            self.gen_multivol (self.VOLUMES)
 
         vname = partial (self.default_volume_name, backup_file)
         dtar = deltatar.DeltaTar (mode=mode,
@@ -434,19 +438,7 @@ class RescueTest (DefectiveTest):
             self.gen_file_names (self.COMPRESSION, self.PASSWORD)
 
         if self.VOLUMES > 1:
-            # add n files for one nth the volume size each, corrected
-            # for metadata and tar block overhead
-            fsiz = int (  (  TEST_VOLSIZ
-                           / (TEST_FILESPERVOL * VOLUME_OVERHEAD))
-                        * 1024 * 1024)
-            fcnt = (self.VOLUMES - 1) * TEST_FILESPERVOL
-            for i in range (fcnt):
-                nvol, invol = divmod(i, TEST_FILESPERVOL)
-                f = "dummy_vol_%d_n_%0.2d" % (nvol, invol)
-                self.hash [f] = self.create_file ("%s/%s"
-                                                  % (self.src_path, f),
-                                                  fsiz,
-                                                  random=True)
+            self.gen_multivol (self.VOLUMES)
 
         vname = partial (self.default_volume_name, backup_file)
         dtar = deltatar.DeltaTar (mode=mode,
@@ -534,6 +526,9 @@ class GenIndexTest (DefectiveTest):
         bak_path, backup_file, backup_full, index_file = \
             self.gen_file_names (self.COMPRESSION, self.PASSWORD)
 
+        if self.VOLUMES > 1:
+            self.gen_multivol (self.VOLUMES)
+
         vname = partial (self.default_volume_name, backup_file)
         dtar = deltatar.DeltaTar (mode=mode,
                                   logger=None,
@@ -552,7 +547,9 @@ class GenIndexTest (DefectiveTest):
                                           mode,
                                           password=self.PASSWORD)
 
-        assert len (psidx) == len (self.hash)
+        # correct for objects spanning volumes: these are treated as separate
+        # in the index!
+        assert len (psidx) - self.VOLUMES + 1 == len (self.hash)
 
 
 ###############################################################################
@@ -856,15 +853,29 @@ class GenIndexIntactBaseTest (GenIndexTest):
     VOLUMES     = 1
     MISMATCHES  = 1
 
+class GenIndexIntactSingleTest (GenIndexIntactBaseTest):
+    pass
+
+class GenIndexIntactSingleGZTest (GenIndexIntactBaseTest):
+    COMPRESSION = "#gz"
+    MISSING     = 2
+
+class GenIndexIntactSingleGZAESTest (GenIndexIntactBaseTest):
+    COMPRESSION = "#gz"
+    PASSWORD    = TEST_PASSWORD
+    MISSING     = 2
 
-class GenIndexIntactTest (GenIndexIntactBaseTest):
+class GenIndexIntactMultiTest (GenIndexIntactBaseTest):
+    VOLUMES     = 3
     pass
 
-class GenIndexIntactGZTest (GenIndexIntactBaseTest):
+class GenIndexIntactMultiGZTest (GenIndexIntactBaseTest):
+    VOLUMES     = 3
     COMPRESSION = "#gz"
     MISSING     = 2
 
-class GenIndexIntactGZAESTest (GenIndexIntactBaseTest):
+class GenIndexIntactMultiGZAESTest (GenIndexIntactBaseTest):
+    VOLUMES     = 3
     COMPRESSION = "#gz"
     PASSWORD    = TEST_PASSWORD
     MISSING     = 2