This commit is contained in:
2026-03-16 08:06:25 +02:00
parent 78d4064853
commit d0f8315cf1
35 changed files with 2493 additions and 624 deletions

View File

@@ -16,7 +16,14 @@ from flow.domain.remote.resolution import (
class TestParseTarget:
def test_valid_spec(self):
ns, plat = parse_target("personal@orb")
user, ns, plat = parse_target("personal@orb")
assert user is None
assert ns == "personal"
assert plat == "orb"
def test_valid_spec_with_user(self):
user, ns, plat = parse_target("alice@personal@orb")
assert user == "alice"
assert ns == "personal"
assert plat == "orb"
@@ -32,33 +39,40 @@ class TestParseTarget:
class TestResolveTarget:
def test_found(self):
targets = [TargetConfig(namespace="personal", platform="orb", host="personal.orb")]
result = resolve_target("personal@orb", targets)
result = resolve_target("personal@orb", targets, default_user="tomas")
assert result.host == "personal.orb"
assert result.label == "personal@orb"
assert result.user == "tomas"
def test_not_found(self):
with pytest.raises(FlowError, match="Unknown target"):
resolve_target("missing@host", [])
resolve_target("missing@host", [], default_user="tomas")
def test_falls_back_to_host_template(self):
result = resolve_target("personal@orb", [], default_user="tomas")
assert result.host == "personal.orb"
class TestBuildSSHCommand:
def test_basic(self):
target = Target(namespace="personal", platform="orb", host="personal.orb")
target = Target(namespace="personal", platform="orb", host="personal.orb", user="tomas")
cmd = build_ssh_command(target)
assert "ssh" in cmd.argv
assert "personal.orb" in cmd.argv
assert cmd.destination == "tomas@personal.orb"
assert cmd.env["DF_NAMESPACE"] == "personal"
assert "tmux" in cmd.argv
def test_with_identity(self):
target = Target(namespace="work", platform="ec2", host="work.ec2", identity="~/.ssh/id_work")
target = Target(namespace="work", platform="ec2", host="work.ec2", identity="~/.ssh/id_work", user="tomas")
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"
def test_without_tmux(self):
target = Target(namespace="p", platform="o", host="h", user="tomas")
cmd = build_ssh_command(target, no_tmux=True)
assert "tmux" not in cmd.argv
assert cmd.destination == "tomas@h"
class TestListTargets:
@@ -73,7 +87,6 @@ class TestListTargets:
class TestTerminfoFix:
def test_returns_commands(self):
cmds = terminfo_fix_command()
assert len(cmds) == 2
assert "infocmp" in cmds[0]
def test_returns_command(self):
cmd = terminfo_fix_command()
assert "infocmp" in cmd