Motivation: local builds and deployments without ssh Add a new interface `Host` which is implemented bei either `Remote` or `Localhost` This simplifies all interactions with hosts. THe caller does ot need to know if the Host is remote or local in mot cases anymore
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Test script for Host interface with LocalHost implementation."""
|
|
|
|
from clan_lib.cmd import RunOpts
|
|
from clan_lib.ssh.host import Host
|
|
from clan_lib.ssh.localhost import LocalHost
|
|
|
|
|
|
def test_localhost() -> None:
|
|
# Create LocalHost instance
|
|
localhost = LocalHost(command_prefix="local-test")
|
|
|
|
# Verify it's a Host instance
|
|
assert isinstance(localhost, Host), "LocalHost should be an instance of Host"
|
|
|
|
# Test basic command execution
|
|
result = localhost.run(["echo", "Hello from LocalHost"])
|
|
assert result.returncode == 0, f"Command failed with code {result.returncode}"
|
|
assert result.stdout.strip() == "Hello from LocalHost", (
|
|
f"Unexpected output: {result.stdout}"
|
|
)
|
|
|
|
# Test with environment variable
|
|
result = localhost.run(
|
|
["printenv", "TEST_VAR"],
|
|
opts=RunOpts(check=False), # Don't check return code
|
|
extra_env={"TEST_VAR": "LocalHost works!"},
|
|
)
|
|
assert result.returncode == 0, f"Command failed with code {result.returncode}"
|
|
assert result.stdout.strip() == "LocalHost works!", (
|
|
f"Expected 'LocalHost works!', got '{result.stdout.strip()}'"
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_localhost()
|