tests/objectstore: check tracking of objects

Ensure all objects are properly cleaned up when ObjectStore is
used as a context manager and the context is exited.
This commit is contained in:
Christian Kellner 2020-03-05 18:52:22 +01:00 committed by Tom Gundersen
parent 856698ee9c
commit 01efa9f817

View file

@ -61,6 +61,18 @@ class TestObjectStore(unittest.TestCase):
self.assertEqual(object_store.resolve_ref("a"),
f"{object_store.refs}/a")
def test_cleanup(self):
# always use a temporary store so item counting works
with tempfile.TemporaryDirectory(dir="/var/tmp") as tmp:
with objectstore.ObjectStore(tmp) as object_store:
tree = object_store.new()
self.assertEqual(len(os.listdir(object_store.tmp)), 1)
with tree.write() as path:
p = Path(f"{path}/A")
p.touch()
# there should be no temporary Objects dirs anymore
self.assertEqual(len(os.listdir(object_store.tmp)), 0)
def test_duplicate(self):
with tempfile.TemporaryDirectory(dir="/var/tmp") as tmp:
object_store = objectstore.ObjectStore(tmp)