Add test coverage for audit_location_generator yield_hashes arg
Add unit test coverage for the optional yield_hash_dirs arg added to audit_location_generator in [1]. [1] Related-Change: I6e01ed29eb8971eeff96887efbfdfb76a01b00c3 Change-Id: Ibd738365112e0efcb9a7dad73cf4a09f1c3236bc
This commit is contained in:
parent
59239af2b2
commit
42f4af45ae
@ -6259,6 +6259,7 @@ class TestAuditLocationGenerator(unittest.TestCase):
|
|||||||
def test_find_objects(self):
|
def test_find_objects(self):
|
||||||
with temptree([]) as tmpdir:
|
with temptree([]) as tmpdir:
|
||||||
expected_objs = list()
|
expected_objs = list()
|
||||||
|
expected_dirs = list()
|
||||||
logger = FakeLogger()
|
logger = FakeLogger()
|
||||||
data = os.path.join(tmpdir, "drive", "data")
|
data = os.path.join(tmpdir, "drive", "data")
|
||||||
os.makedirs(data)
|
os.makedirs(data)
|
||||||
@ -6270,6 +6271,7 @@ class TestAuditLocationGenerator(unittest.TestCase):
|
|||||||
os.makedirs(suffix)
|
os.makedirs(suffix)
|
||||||
hash_path = os.path.join(suffix, "hash")
|
hash_path = os.path.join(suffix, "hash")
|
||||||
os.makedirs(hash_path)
|
os.makedirs(hash_path)
|
||||||
|
expected_dirs.append((hash_path, 'drive', 'partition1'))
|
||||||
obj_path = os.path.join(hash_path, "obj1.db")
|
obj_path = os.path.join(hash_path, "obj1.db")
|
||||||
with open(obj_path, "w"):
|
with open(obj_path, "w"):
|
||||||
pass
|
pass
|
||||||
@ -6280,6 +6282,7 @@ class TestAuditLocationGenerator(unittest.TestCase):
|
|||||||
os.makedirs(suffix)
|
os.makedirs(suffix)
|
||||||
hash_path = os.path.join(suffix, "hash2")
|
hash_path = os.path.join(suffix, "hash2")
|
||||||
os.makedirs(hash_path)
|
os.makedirs(hash_path)
|
||||||
|
expected_dirs.append((hash_path, 'drive', 'partition2'))
|
||||||
obj_path = os.path.join(hash_path, "obj2.db")
|
obj_path = os.path.join(hash_path, "obj2.db")
|
||||||
with open(obj_path, "w"):
|
with open(obj_path, "w"):
|
||||||
pass
|
pass
|
||||||
@ -6292,6 +6295,14 @@ class TestAuditLocationGenerator(unittest.TestCase):
|
|||||||
self.assertEqual(sorted(got_objs), sorted(expected_objs))
|
self.assertEqual(sorted(got_objs), sorted(expected_objs))
|
||||||
self.assertEqual(1, len(logger.get_lines_for_level('warning')))
|
self.assertEqual(1, len(logger.get_lines_for_level('warning')))
|
||||||
|
|
||||||
|
# check yield_hash_dirs option
|
||||||
|
locations = utils.audit_location_generator(
|
||||||
|
tmpdir, "data", mount_check=False, logger=logger,
|
||||||
|
yield_hash_dirs=True,
|
||||||
|
)
|
||||||
|
got_dirs = list(locations)
|
||||||
|
self.assertEqual(sorted(got_dirs), sorted(expected_dirs))
|
||||||
|
|
||||||
def test_ignore_metadata(self):
|
def test_ignore_metadata(self):
|
||||||
with temptree([]) as tmpdir:
|
with temptree([]) as tmpdir:
|
||||||
logger = FakeLogger()
|
logger = FakeLogger()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user