1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
"""
Test the verify action with api version >= 201
"""
import os
import unittest
import commontest as comtst
import fileset
class ActionVerifyTest(unittest.TestCase):
"""
Test that rdiff-backup properly verifies repositories
"""
def setUp(self):
self.base_dir = os.path.join(comtst.abs_test_dir, b"action_verify")
self.from1_struct = {
"from1": {"contents": {
"fileChanged": {"content": "initial"},
"fileOld": {},
"fileUnchanged": {"content": "unchanged"},
}}
}
self.from1_path = os.path.join(self.base_dir, b"from1")
self.from2_struct = {
"from2": {"contents": {
"fileChanged": {"content": "modified"},
"fileNew": {},
"fileUnchanged": {"content": "unchanged"},
}}
}
self.from2_path = os.path.join(self.base_dir, b"from2")
fileset.create_fileset(self.base_dir, self.from1_struct)
fileset.create_fileset(self.base_dir, self.from2_struct)
fileset.remove_fileset(self.base_dir, {"bak": {"type": "dir"}})
self.bak_path = os.path.join(self.base_dir, b"bak")
self.success = False
# we backup to the same backup repository at different times
comtst.rdiff_backup_action(
True, True, self.from1_path, self.bak_path,
("--api-version", "201", "--current-time", "10000"),
b"backup", ())
comtst.rdiff_backup_action(
True, True, self.from2_path, self.bak_path,
("--api-version", "201", "--current-time", "20000"),
b"backup", ())
def test_action_verify(self):
"""test different ways of verifying"""
# removing multiple increments fails without --force
self.assertEqual(comtst.rdiff_backup_action(
False, None, self.bak_path, None,
("--api-version", "201"),
b"verify", ()), 0)
self.assertEqual(comtst.rdiff_backup_action(
True, None, self.bak_path, None,
("--api-version", "201", "--force"), # now forcing!
b"verify", ("--at", "1B")), 0)
# corrupt the backup repository
with open(os.path.join(self.bak_path, b"fileNew"), "w") as fd:
fd.write("corrupt data")
self.assertNotEqual(comtst.rdiff_backup_action(
False, None, self.bak_path, None,
("--api-version", "201"),
b"verify", ("--at", "now")), 0)
# all tests were successful
self.success = True
def tearDown(self):
# we clean-up only if the test was successful
if self.success:
fileset.remove_fileset(self.base_dir, self.from1_struct)
fileset.remove_fileset(self.base_dir, self.from2_struct)
fileset.remove_fileset(self.base_dir, {"bak": {"type": "dir"}})
if __name__ == "__main__":
unittest.main()
|