Files
flow/tests/test_domain_remote.py
Tomas Mirchev 31d7583b9a 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>
2026-03-16 04:54:06 +02:00

80 lines
2.4 KiB
Python

"""Tests for remote domain."""
import pytest
from flow.core.config import TargetConfig
from flow.core.errors import FlowError
from flow.domain.remote.models import SSHCommand, Target
from flow.domain.remote.resolution import (
build_ssh_command,
list_targets,
parse_target,
resolve_target,
terminfo_fix_command,
)
class TestParseTarget:
def test_valid_spec(self):
ns, plat = parse_target("personal@orb")
assert ns == "personal"
assert plat == "orb"
def test_missing_at_raises(self):
with pytest.raises(FlowError):
parse_target("invalid")
def test_empty_parts_raises(self):
with pytest.raises(FlowError):
parse_target("@orb")
class TestResolveTarget:
def test_found(self):
targets = [TargetConfig(namespace="personal", platform="orb", host="personal.orb")]
result = resolve_target("personal@orb", targets)
assert result.host == "personal.orb"
assert result.label == "personal@orb"
def test_not_found(self):
with pytest.raises(FlowError, match="Unknown target"):
resolve_target("missing@host", [])
class TestBuildSSHCommand:
def test_basic(self):
target = Target(namespace="personal", platform="orb", host="personal.orb")
cmd = build_ssh_command(target)
assert "ssh" in cmd.argv
assert "personal.orb" in cmd.argv
assert cmd.env["DF_NAMESPACE"] == "personal"
def test_with_identity(self):
target = Target(namespace="work", platform="ec2", host="work.ec2", identity="~/.ssh/id_work")
cmd = build_ssh_command(target)
assert "-i" in cmd.argv
assert "~/.ssh/id_work" in cmd.argv
def test_with_remote_command(self):
target = Target(namespace="p", platform="o", host="h")
cmd = build_ssh_command(target, remote_command="ls -la")
assert cmd.argv[-1] == "ls -la"
class TestListTargets:
def test_converts_configs(self):
configs = [
TargetConfig(namespace="a", platform="b", host="a.b"),
TargetConfig(namespace="c", platform="d", host="c.d"),
]
targets = list_targets(configs)
assert len(targets) == 2
assert targets[0].label == "a@b"
class TestTerminfoFix:
def test_returns_commands(self):
cmds = terminfo_fix_command()
assert len(cmds) == 2
assert "infocmp" in cmds[0]