tests: new object store unit test

Basic functional checks, including the new snapshot support.
This commit is contained in:
Christian Kellner 2020-01-27 14:44:28 +01:00 committed by Tom Gundersen
parent ce5719a03f
commit 1cf0e944c9
2 changed files with 48 additions and 1 deletions

45
test/test_objectstore.py Normal file
View file

@ -0,0 +1,45 @@
import os
import shutil
import tempfile
import unittest
from pathlib import Path
from osbuild import objectstore
class TestObjectStore(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.store = os.getenv("OSBUILD_TEST_STORE")
if not cls.store:
cls.store = tempfile.mkdtemp(prefix="osbuild-test-", dir="/var/tmp")
@classmethod
def tearDownClass(cls):
if not os.getenv("OSBUILD_TEST_STORE"):
shutil.rmtree(cls.store)
def test_snapshot(self):
object_store = objectstore.ObjectStore(self.store)
with object_store.new("b") as tree:
p = Path(f"{tree}/A")
p.touch()
object_store.snapshot(tree, "a")
p = Path(f"{tree}/B")
p.touch()
# check the references exist
assert os.path.exists(f"{object_store.refs}/a")
assert os.path.exists(f"{object_store.refs}/b")
# check the contents of the trees
assert os.path.exists(f"{object_store.refs}/a/A")
assert not os.path.exists(f"{object_store.refs}/a/B")
assert os.path.exists(f"{object_store.refs}/b/A")
assert os.path.exists(f"{object_store.refs}/b/B")
if __name__ == "__main__":
unittest.main()