Files
flow/tests/test_service_remote.py

58 lines
1.8 KiB
Python

"""Tests for RemoteService."""
import pytest
from flow.core.config import AppConfig, FlowContext, TargetConfig
from flow.core.console import Console
from flow.core.errors import FlowError
from flow.core.platform import PlatformInfo
from flow.core.runtime import SystemRuntime
from flow.app.remote import RemoteService
def _make_ctx(targets=None):
return FlowContext(
config=AppConfig(targets=targets or []),
manifest={},
platform=PlatformInfo(),
console=Console(color=False),
runtime=SystemRuntime(),
)
class TestRemoteService:
def test_enter_dry_run(self, capsys):
targets = [TargetConfig(namespace="personal", platform="orb", host="personal.orb")]
ctx = _make_ctx(targets)
svc = RemoteService(ctx)
svc.enter("personal@orb", dry_run=True)
output = capsys.readouterr().out
assert "personal@orb" in output
assert "ssh" in output
assert "tmux" in output
assert "DF_NAMESPACE=personal" in output
def test_enter_unknown_target(self):
ctx = _make_ctx()
svc = RemoteService(ctx)
with pytest.raises(FlowError, match="Unknown target"):
svc.enter("missing@host")
def test_list_targets(self, capsys):
targets = [
TargetConfig(namespace="personal", platform="orb", host="personal.orb"),
TargetConfig(namespace="work", platform="ec2", host="work.ec2"),
]
ctx = _make_ctx(targets)
svc = RemoteService(ctx)
svc.list()
output = capsys.readouterr().out
assert "personal@orb" in output
assert "work@ec2" in output
def test_list_empty(self, capsys):
ctx = _make_ctx()
svc = RemoteService(ctx)
svc.list()
assert "No targets" in capsys.readouterr().out