VMs: ensure state dirs don't collide between clans

This commit is contained in:
DavHau
2024-01-09 16:53:52 +07:00
parent 2566fccfcf
commit 520ff0b334
4 changed files with 31 additions and 13 deletions

View File

@@ -15,3 +15,21 @@
# monkeypatch.chdir(subdir)
# (subdir / ".clan-flake").touch()
# assert _get_clan_flake_toplevel() == subdir
from clan_cli.dirs import clan_key_safe, vm_state_dir
def test_clan_key_safe() -> None:
assert clan_key_safe("clan1", "/foo/bar") == "clan1-%2Ffoo%2Fbar"
def test_vm_state_dir_identity() -> None:
dir1 = vm_state_dir("clan1", "https://some.clan", "vm1")
dir2 = vm_state_dir("clan1", "https://some.clan", "vm1")
assert str(dir1) == str(dir2)
def test_vm_state_dir_no_collision() -> None:
dir1 = vm_state_dir("clan1", "/foo/bar", "vm1")
dir2 = vm_state_dir("clan1", "https://some.clan", "vm1")
assert str(dir1) != str(dir2)