Files
triggershell/tests/test_config.py
T

71 lines
1.7 KiB
Python
Raw Normal View History

2026-08-15 18:37:30 +02:00
from pathlib import Path
import pytest
from triggershell.config import ConfigError, preflight_check
def write(tmp_path: Path, content: str) -> Path:
path = tmp_path / "triggershell.yml"
2026-08-15 18:37:30 +02:00
path.write_text(content)
return path
def test_missing_file_raises(tmp_path: Path) -> None:
with pytest.raises(ConfigError, match="not found"):
preflight_check(tmp_path / "missing.yaml")
def test_invalid_yaml_raises(tmp_path: Path) -> None:
path = write(tmp_path, "scripts: [this is not: valid: yaml")
with pytest.raises(ConfigError, match="parse YAML"):
preflight_check(path)
def test_non_mapping_root_raises(tmp_path: Path) -> None:
path = write(tmp_path, "- just\n- a\n- list\n")
with pytest.raises(ConfigError, match="mapping"):
preflight_check(path)
def test_empty_file_is_ok(tmp_path: Path) -> None:
path = write(tmp_path, "")
data = preflight_check(path)
assert data == {}
def test_script_missing_id_raises(tmp_path: Path) -> None:
path = write(tmp_path, "scripts:\n - name: no id here\n")
with pytest.raises(ConfigError, match="missing a non-empty 'id'"):
preflight_check(path)
def test_duplicate_script_id_raises(tmp_path: Path) -> None:
path = write(
tmp_path,
"""
scripts:
- id: dup
name: One
- id: dup
name: Two
""",
)
with pytest.raises(ConfigError, match="duplicate script id"):
preflight_check(path)
def test_valid_minimal_config_passes(tmp_path: Path) -> None:
path = write(
tmp_path,
"""
scripts:
- id: hello
name: Hello
command: echo
""",
)
data = preflight_check(path)
assert len(data["scripts"]) == 1
assert data["scripts"][0]["id"] == "hello"