update
This commit is contained in:
97
tests/test_core_tmux.py
Normal file
97
tests/test_core_tmux.py
Normal file
@@ -0,0 +1,97 @@
|
||||
"""Tests for flow.core.tmux."""
|
||||
|
||||
import subprocess
|
||||
|
||||
from flow.core.tmux import TmuxClient, build_new_session_argv
|
||||
|
||||
from tests.fakes import FakeRunner
|
||||
|
||||
|
||||
class TestTmuxClient:
|
||||
def test_has_session_true(self):
|
||||
runner = FakeRunner({
|
||||
("tmux", "has-session", "-t"): subprocess.CompletedProcess([], 0),
|
||||
})
|
||||
tmux = TmuxClient(runner)
|
||||
assert tmux.has_session("dev-api") is True
|
||||
assert runner.calls[-1] == ["tmux", "has-session", "-t", "dev-api"]
|
||||
|
||||
def test_has_session_false(self):
|
||||
runner = FakeRunner({
|
||||
("tmux", "has-session", "-t"): subprocess.CompletedProcess([], 1),
|
||||
})
|
||||
tmux = TmuxClient(runner)
|
||||
assert tmux.has_session("dev-api") is False
|
||||
|
||||
def test_new_session_detached_with_env_and_command(self):
|
||||
runner = FakeRunner()
|
||||
tmux = TmuxClient(runner)
|
||||
tmux.new_session(
|
||||
"dev-api",
|
||||
detached=True,
|
||||
env={"DF_IMAGE": "reg/img"},
|
||||
command="flow dev exec api",
|
||||
)
|
||||
call = runner.calls[-1]
|
||||
assert call[:4] == ["tmux", "new-session", "-ds", "dev-api"]
|
||||
assert "-e" in call
|
||||
assert "DF_IMAGE=reg/img" in call
|
||||
assert call[-1] == "flow dev exec api"
|
||||
|
||||
def test_new_session_minimal(self):
|
||||
runner = FakeRunner()
|
||||
tmux = TmuxClient(runner)
|
||||
tmux.new_session("sess")
|
||||
assert runner.calls[-1] == ["tmux", "new-session", "-s", "sess"]
|
||||
|
||||
def test_set_option(self):
|
||||
runner = FakeRunner()
|
||||
tmux = TmuxClient(runner)
|
||||
tmux.set_option("dev-api", "default-command", "flow dev exec api")
|
||||
assert runner.calls[-1] == [
|
||||
"tmux", "set-option", "-t", "dev-api", "default-command", "flow dev exec api",
|
||||
]
|
||||
|
||||
def test_list_panes(self):
|
||||
runner = FakeRunner({
|
||||
("tmux", "list-panes", "-t"): subprocess.CompletedProcess(
|
||||
[], 0, stdout="dev-api:0.0\ndev-api:0.1\n",
|
||||
),
|
||||
})
|
||||
tmux = TmuxClient(runner)
|
||||
panes = tmux.list_panes("dev-api")
|
||||
assert panes == ["dev-api:0.0", "dev-api:0.1"]
|
||||
|
||||
def test_list_panes_empty(self):
|
||||
runner = FakeRunner({
|
||||
("tmux", "list-panes", "-t"): subprocess.CompletedProcess([], 0, stdout=""),
|
||||
})
|
||||
tmux = TmuxClient(runner)
|
||||
assert tmux.list_panes("dev-api") == []
|
||||
|
||||
def test_respawn_pane(self):
|
||||
runner = FakeRunner()
|
||||
tmux = TmuxClient(runner)
|
||||
tmux.respawn_pane("dev-api:0.0")
|
||||
assert runner.calls[-1] == ["tmux", "respawn-pane", "-t", "dev-api:0.0"]
|
||||
|
||||
|
||||
class TestBuildNewSessionArgv:
|
||||
def test_basic(self):
|
||||
argv = build_new_session_argv("default")
|
||||
assert argv == ["tmux", "new-session", "-As", "default"]
|
||||
|
||||
def test_with_env(self):
|
||||
argv = build_new_session_argv(
|
||||
"main",
|
||||
env={"DF_NAMESPACE": "personal", "DF_PLATFORM": "orb"},
|
||||
)
|
||||
assert argv == [
|
||||
"tmux", "new-session", "-As", "main",
|
||||
"-e", "DF_NAMESPACE=personal",
|
||||
"-e", "DF_PLATFORM=orb",
|
||||
]
|
||||
|
||||
def test_empty_env(self):
|
||||
argv = build_new_session_argv("sess", env={})
|
||||
assert argv == ["tmux", "new-session", "-As", "sess"]
|
||||
Reference in New Issue
Block a user