feat: add all domain layers (dotfiles, packages, remote, containers)
- Dotfiles: models, module resolution, path resolution, link planning - Packages: models, catalog parsing, resolution, install/remove planning - Remote: target parsing, SSH command building - Containers: image refs, mount resolution, container specs All domain code is pure functions + frozen dataclasses. 88 tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
80
tests/test_domain_containers.py
Normal file
80
tests/test_domain_containers.py
Normal file
@@ -0,0 +1,80 @@
|
||||
"""Tests for containers domain."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from flow.domain.containers.models import ContainerSpec, ImageRef, Mount
|
||||
from flow.domain.containers.resolution import (
|
||||
build_container_spec,
|
||||
container_name,
|
||||
parse_image_ref,
|
||||
resolve_mounts,
|
||||
)
|
||||
|
||||
|
||||
class TestParseImageRef:
|
||||
def test_simple_name(self):
|
||||
ref = parse_image_ref("devbox")
|
||||
assert ref.registry == "registry.tomastm.com"
|
||||
assert ref.name == "devbox"
|
||||
assert ref.tag == "latest"
|
||||
|
||||
def test_with_tag(self):
|
||||
ref = parse_image_ref("devbox:v2")
|
||||
assert ref.tag == "v2"
|
||||
|
||||
def test_full_ref(self):
|
||||
ref = parse_image_ref("ghcr.io/user/image:main")
|
||||
assert ref.registry == "ghcr.io"
|
||||
assert ref.name == "user/image"
|
||||
assert ref.tag == "main"
|
||||
|
||||
def test_full_image_string(self):
|
||||
ref = parse_image_ref("devbox")
|
||||
assert ref.full == "registry.tomastm.com/devbox:latest"
|
||||
|
||||
|
||||
class TestContainerName:
|
||||
def test_basic(self):
|
||||
assert container_name("personal", "devbox") == "flow-personal-devbox"
|
||||
|
||||
|
||||
class TestResolveMounts:
|
||||
def test_projects_mount(self, tmp_path):
|
||||
projects = tmp_path / "projects"
|
||||
projects.mkdir()
|
||||
mounts = resolve_mounts(tmp_path, str(projects))
|
||||
project_mounts = [m for m in mounts if m.target == "/home/user/projects"]
|
||||
assert len(project_mounts) == 1
|
||||
|
||||
def test_extra_mounts(self, tmp_path):
|
||||
mounts = resolve_mounts(
|
||||
tmp_path, str(tmp_path),
|
||||
extra_mounts=[{"source": str(tmp_path), "target": "/data"}],
|
||||
)
|
||||
extra = [m for m in mounts if m.target == "/data"]
|
||||
assert len(extra) == 1
|
||||
|
||||
|
||||
class TestBuildContainerSpec:
|
||||
def test_basic(self):
|
||||
image = ImageRef(registry="reg", name="img", tag="v1")
|
||||
spec = build_container_spec("personal", image, [])
|
||||
assert spec.name == "flow-personal-img"
|
||||
assert spec.env["DF_NAMESPACE"] == "personal"
|
||||
assert spec.env["DF_PLATFORM"] == "container"
|
||||
|
||||
def test_with_mounts(self):
|
||||
image = ImageRef(registry="reg", name="img", tag="v1")
|
||||
mounts = [Mount(source=Path("/a"), target="/b")]
|
||||
spec = build_container_spec("ns", image, mounts)
|
||||
assert len(spec.mounts) == 1
|
||||
|
||||
|
||||
class TestMount:
|
||||
def test_to_flag(self):
|
||||
m = Mount(source=Path("/src"), target="/dst")
|
||||
assert m.to_flag() == "-v /src:/dst"
|
||||
|
||||
def test_to_flag_readonly(self):
|
||||
m = Mount(source=Path("/src"), target="/dst", readonly=True)
|
||||
assert ":ro" in m.to_flag()
|
||||
Reference in New Issue
Block a user