flow
This commit is contained in:
153
tests/test_cli.py
Normal file
153
tests/test_cli.py
Normal file
@@ -0,0 +1,153 @@
|
||||
"""Tests for CLI routing and command registration."""
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
def _clean_env():
|
||||
"""Return env dict without DF_* variables that trigger enter's guard."""
|
||||
return {k: v for k, v in os.environ.items() if not k.startswith("DF_")}
|
||||
|
||||
|
||||
def test_version():
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-m", "flow", "--version"],
|
||||
capture_output=True, text=True,
|
||||
)
|
||||
assert result.returncode == 0
|
||||
assert "0.1.0" in result.stdout
|
||||
|
||||
|
||||
def test_help():
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-m", "flow", "--help"],
|
||||
capture_output=True, text=True,
|
||||
)
|
||||
assert result.returncode == 0
|
||||
assert "enter" in result.stdout
|
||||
assert "dev" in result.stdout
|
||||
assert "dotfiles" in result.stdout
|
||||
assert "bootstrap" in result.stdout
|
||||
assert "package" in result.stdout
|
||||
assert "sync" in result.stdout
|
||||
assert "completion" in result.stdout
|
||||
|
||||
|
||||
def test_enter_help():
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-m", "flow", "enter", "--help"],
|
||||
capture_output=True, text=True,
|
||||
)
|
||||
assert result.returncode == 0
|
||||
assert "target" in result.stdout
|
||||
assert "--dry-run" in result.stdout
|
||||
|
||||
|
||||
def test_dotfiles_help():
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-m", "flow", "dotfiles", "--help"],
|
||||
capture_output=True, text=True,
|
||||
)
|
||||
assert result.returncode == 0
|
||||
assert "init" in result.stdout
|
||||
assert "link" in result.stdout
|
||||
assert "unlink" in result.stdout
|
||||
assert "status" in result.stdout
|
||||
assert "sync" in result.stdout
|
||||
|
||||
|
||||
def test_bootstrap_help():
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-m", "flow", "bootstrap", "--help"],
|
||||
capture_output=True, text=True,
|
||||
)
|
||||
assert result.returncode == 0
|
||||
assert "run" in result.stdout
|
||||
assert "list" in result.stdout
|
||||
assert "show" in result.stdout
|
||||
|
||||
|
||||
def test_package_help():
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-m", "flow", "package", "--help"],
|
||||
capture_output=True, text=True,
|
||||
)
|
||||
assert result.returncode == 0
|
||||
assert "install" in result.stdout
|
||||
assert "list" in result.stdout
|
||||
assert "remove" in result.stdout
|
||||
|
||||
|
||||
def test_sync_help():
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-m", "flow", "sync", "--help"],
|
||||
capture_output=True, text=True,
|
||||
)
|
||||
assert result.returncode == 0
|
||||
assert "check" in result.stdout
|
||||
assert "fetch" in result.stdout
|
||||
assert "summary" in result.stdout
|
||||
|
||||
|
||||
def test_dev_help():
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-m", "flow", "dev", "--help"],
|
||||
capture_output=True, text=True,
|
||||
)
|
||||
assert result.returncode == 0
|
||||
assert "create" in result.stdout
|
||||
assert "exec" in result.stdout
|
||||
assert "connect" in result.stdout
|
||||
assert "list" in result.stdout
|
||||
assert "stop" in result.stdout
|
||||
assert "remove" in result.stdout
|
||||
assert "respawn" in result.stdout
|
||||
|
||||
|
||||
def test_enter_dry_run():
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-m", "flow", "enter", "--dry-run", "personal@orb"],
|
||||
capture_output=True, text=True, env=_clean_env(),
|
||||
)
|
||||
assert result.returncode == 0
|
||||
assert "ssh" in result.stdout
|
||||
assert "personal.orb" in result.stdout
|
||||
assert "tmux" in result.stdout
|
||||
|
||||
|
||||
def test_enter_dry_run_no_tmux():
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-m", "flow", "enter", "--dry-run", "--no-tmux", "personal@orb"],
|
||||
capture_output=True, text=True, env=_clean_env(),
|
||||
)
|
||||
assert result.returncode == 0
|
||||
assert "ssh" in result.stdout
|
||||
assert "tmux" not in result.stdout
|
||||
|
||||
|
||||
def test_enter_dry_run_with_user():
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-m", "flow", "enter", "--dry-run", "root@personal@orb"],
|
||||
capture_output=True, text=True, env=_clean_env(),
|
||||
)
|
||||
assert result.returncode == 0
|
||||
assert "root@personal.orb" in result.stdout
|
||||
|
||||
|
||||
def test_aliases():
|
||||
"""Test that command aliases work."""
|
||||
for alias, cmd in [("dot", "dotfiles"), ("pkg", "package"), ("setup", "bootstrap")]:
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-m", "flow", alias, "--help"],
|
||||
capture_output=True, text=True,
|
||||
)
|
||||
assert result.returncode == 0, f"Alias '{alias}' failed"
|
||||
|
||||
|
||||
def test_dev_remove_alias():
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-m", "flow", "dev", "rm", "--help"],
|
||||
capture_output=True, text=True,
|
||||
)
|
||||
assert result.returncode == 0
|
||||
Reference in New Issue
Block a user