test(inventory/store): clean up simple test

This commit is contained in:
Johannes Kirschbauer
2025-05-23 21:38:16 +02:00
parent 6cd2c1ce1a
commit 3f82ceddb3

View File

@@ -67,32 +67,36 @@ class MockFlake:
folder_path = Path(__file__).parent.resolve()
def test_for_johannes() -> None:
nix_file = folder_path / "fixtures/1.nix"
json_file = folder_path / "fixtures/1.json"
def test_simple_read_write() -> None:
entry_file = "1.nix"
inventory_file = entry_file.replace(".nix", ".json")
nix_file = folder_path / f"fixtures/{entry_file}"
json_file = folder_path / f"fixtures/{inventory_file}"
with TemporaryDirectory() as tmp:
shutil.copyfile(
str(nix_file),
str(Path(tmp) / "1.nix"),
str(Path(tmp) / entry_file),
)
shutil.copyfile(
str(json_file),
str(Path(tmp) / "1.json"),
str(Path(tmp) / inventory_file),
)
store = InventoryStore(
flake=MockFlake(Path(tmp) / "1.nix"),
inventory_file_name="1.json",
flake=MockFlake(Path(tmp) / entry_file),
inventory_file_name=inventory_file,
)
assert store.read() == {"foo": "bar", "protected": "protected"}
data: dict = store.read() # type: ignore
assert data == {"foo": "bar", "protected": "protected"}
data = {"foo": "foo"}
apply_patch(data, "foo", "foo") # type: ignore
store.write(data, "test", commit=False) # type: ignore
# Default method to access the inventory
assert store.read() == {"foo": "foo", "protected": "protected"}
# Test the data is actually persisted
assert store._get_persisted() == data
assert store._get_persisted() == {"foo": "foo"}
# clan_lib.errors.ClanError: Key 'protected' is not writeable.
invalid_data = {"protected": "foo"}
@@ -101,8 +105,8 @@ def test_for_johannes() -> None:
assert str(e.value) == "Key 'protected' is not writeable."
# Test the data is not touched
assert store.read() == {"foo": "foo", "protected": "protected"}
assert store._get_persisted() == data
assert store.read() == data
assert store._get_persisted() == {"foo": "foo"}
# Remove the foo key from the persisted data
# Technically data = { } should also work