Add Docker exec PTY sessions
This commit is contained in:
@@ -6,7 +6,12 @@ from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from webterm.docker_watcher import LABEL_NAME, THEME_LABEL, DockerWatcher, _get_auto_command
|
||||
from webterm.docker_watcher import (
|
||||
AUTO_COMMAND_SENTINEL,
|
||||
LABEL_NAME,
|
||||
THEME_LABEL,
|
||||
DockerWatcher,
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -56,8 +61,7 @@ class TestDockerWatcher:
|
||||
def test_get_container_command_auto(self, docker_watcher):
|
||||
"""Test command generation when label is 'auto'."""
|
||||
container = {"Names": ["/my-container"], "Labels": {LABEL_NAME: "auto"}}
|
||||
expected = f"docker exec -it my-container {_get_auto_command()}"
|
||||
assert docker_watcher._get_container_command(container) == expected
|
||||
assert docker_watcher._get_container_command(container) == AUTO_COMMAND_SENTINEL
|
||||
|
||||
def test_get_container_command_custom(self, docker_watcher):
|
||||
"""Test command when label has custom value."""
|
||||
@@ -93,7 +97,7 @@ class TestDockerWatcher:
|
||||
session_manager.add_app.assert_called_once()
|
||||
call_args = session_manager.add_app.call_args
|
||||
assert call_args[0][0] == "test-container" # name
|
||||
assert "docker exec -it test-container" in call_args[0][1] # command
|
||||
assert call_args[0][1] == AUTO_COMMAND_SENTINEL # command
|
||||
assert call_args[0][2] == "test-container" # slug
|
||||
assert call_args[1]["terminal"] is True
|
||||
assert call_args[1]["theme"] == "monokai"
|
||||
@@ -235,8 +239,9 @@ class TestDockerWatcherIntegration:
|
||||
("labels", "expected"),
|
||||
[
|
||||
({"webterm-command": "echo hi"}, "echo hi"),
|
||||
({"webterm-command": "auto"}, f"docker exec -it my-container {_get_auto_command()}"),
|
||||
({"other": "value"}, f"docker exec -it my-container {_get_auto_command()}"),
|
||||
({"webterm-command": "auto"}, AUTO_COMMAND_SENTINEL),
|
||||
({"webterm-command": ""}, AUTO_COMMAND_SENTINEL),
|
||||
({"other": "value"}, AUTO_COMMAND_SENTINEL),
|
||||
],
|
||||
)
|
||||
def test_get_container_command_variants(docker_watcher, labels, expected):
|
||||
@@ -247,7 +252,7 @@ def test_get_container_command_variants(docker_watcher, labels, expected):
|
||||
def test_auto_command_env_override(monkeypatch, docker_watcher):
|
||||
monkeypatch.setenv("WEBTERM_DOCKER_AUTO_COMMAND", "/bin/sh")
|
||||
container = {"Names": ["/my-container"], "Labels": {LABEL_NAME: "auto"}}
|
||||
assert docker_watcher._get_container_command(container) == "docker exec -it my-container /bin/sh"
|
||||
assert docker_watcher._get_container_command(container) == AUTO_COMMAND_SENTINEL
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user