track irrecoverable files in test_recover
authorPhilipp Gesang <philipp.gesang@intra2net.com>
Thu, 10 Aug 2017 12:39:40 +0000 (14:39 +0200)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Mon, 2 Apr 2018 11:34:09 +0000 (13:34 +0200)
testing/test_recover.py

index a5b37c4..5c84783 100644 (file)
@@ -106,8 +106,8 @@ class RecoverTest (BaseTest):
         self.hash = dict ()
         os.makedirs (src_path)
         for i in range (5):
-            f = "source_dir2/dummy_%rd" % i
-            self.hash [f] = self.create_file (f, 5 + i)
+            f = "dummy_%rd" % i
+            self.hash [f] = self.create_file ("%s/%s" % (src_path, f), 5 + i)
 
         dtar.create_full_backup \
             (source_path=src_path, backup_path=bak_path)
@@ -116,33 +116,40 @@ class RecoverTest (BaseTest):
         dtar.restore_backup(target_path=dst_path,
                             backup_tar_path=backup_full)
         for key, value in self.hash.items ():
-            assert os.path.exists (key)
-            assert value == self.md5sum (key)
+            f = "%s/%s" % (dst_path, key)
+            assert os.path.exists (f)
+            assert value == self.md5sum (f)
+        shutil.rmtree (dst_path)
         shutil.rmtree (src_path)
 
         flip_bits (backup_full, gz_header_size (backup_full) + 1)
 
         # normal restore must fail
         curdir = os.getcwd () # not restored after below failure
-        with self.assertRaises (tarfile.ReadError):
+        with self.assertRaises (Exception) as cm:
             dtar.restore_backup(target_path=dst_path,
                                 backup_tar_path=backup_full)
+        assert type (cm.exception) in [ tarfile.CompressionError
+                                      , tarfile.ReadError
+                                      ]
 
         os.chdir (curdir)
         # but recover will succeed
-        dtar.recover_backup(target_path=dst_path,
-                            backup_indexes_paths=[
-                                "%s/%s" % (bak_path, index_file)
-                            ])
+        failed = dtar.recover_backup(target_path=dst_path,
+                                     backup_indexes_paths=[
+                                         "%s/%s" % (bak_path, index_file)
+                                     ])
+        assert len (failed) == 1
 
         # with one file missing
         missing = []
         for key, value in self.hash.items ():
-            if os.path.exists (key):
-                assert value == self.md5sum (key)
+            kkey = "%s/%s" % (dst_path, key)
+            if os.path.exists (kkey):
+                assert value == self.md5sum (kkey)
             else:
                 missing.append (key)
         assert len (missing) == 1
 
-        shutil.rmtree (src_path)
+        shutil.rmtree (dst_path)