tests: check basic properties of objectstore

Check the very basic operations of the object store, i.e. creating
multiple trees with different object_ids works and results in the
correct number of objects and references.
This commit is contained in:
Christian Kellner 2020-01-27 17:39:53 +01:00 committed by Tom Gundersen
parent 1cf0e944c9
commit 4fe69b756f

View file

@ -20,6 +20,33 @@ class TestObjectStore(unittest.TestCase):
if not os.getenv("OSBUILD_TEST_STORE"):
shutil.rmtree(cls.store)
def test_basic(self):
# always use a temporary store so item counting works
with tempfile.TemporaryDirectory(dir="/var/tmp") as tmp:
object_store = objectstore.ObjectStore(tmp)
with object_store.new("a") as tree:
p = Path(f"{tree}/A")
p.touch()
assert os.path.exists(f"{object_store.refs}/a")
assert os.path.exists(f"{object_store.refs}/a/A")
assert len(os.listdir(object_store.refs)) == 1
assert len(os.listdir(object_store.objects)) == 1
assert len(os.listdir(f"{object_store.refs}/a/")) == 1
with object_store.new("b") as tree:
p = Path(f"{tree}/A")
p.touch()
p = Path(f"{tree}/B")
p.touch()
assert os.path.exists(f"{object_store.refs}/b")
assert os.path.exists(f"{object_store.refs}/b/B")
assert len(os.listdir(object_store.refs)) == 2
assert len(os.listdir(object_store.objects)) == 2
assert len(os.listdir(f"{object_store.refs}/b/")) == 2
def test_snapshot(self):
object_store = objectstore.ObjectStore(self.store)
with object_store.new("b") as tree: