Files
computer-playbook/tests/unit/python/cli/meta/domains/test_main.py
T
kevinveenbirkenbachandClaude Opus 5 af605b049f refactor(domains): give local testing a .test domain, leave .example to docs
RFC 6761 reserves .test for testing and .example for documentation, and the
project's own domain was doing both jobs under the documentation name. It is
what default.env hands every local deploy and what the test fixtures assert
against, so it is a testing name.

Rename it wherever it stands for the running machine: the environment
defaults, the development inventory, the workspace and trust scripts, the test
suites, and the four documents that describe real behaviour - the DNS mapping
to loopback, the browser CA trust, WSL2 resolution. Those documents would have
started lying the moment default.env changed.

The sandbox allowlist moves with them, since egress is matched per pattern and
nothing resolves the old name any more, and the sandbox document that mirrors
that list follows it.

Two places keep .example on purpose: the link-style sample in the
documentation guide, which is documentation about documentation, and every
generic fixture name elsewhere in the suite - a.example, foo.example and their
kin. Those are a larger sweep of their own and are not touched here.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-02 13:10:34 +02:00

86 lines
2.8 KiB
Python

from __future__ import annotations
import io
import tempfile
from pathlib import Path
from unittest import TestCase, main
from unittest.mock import patch
import cli.meta.domains.__main__ as mod
from utils.cache.yaml import dump_yaml_str
from utils.roles.mapping import ROLE_FILE_META_DOMAINS, ROLE_FILE_VARS_MAIN
class TestCliMetaApplicationsDomains(TestCase):
def write_role(
self, roles_dir: Path, role_name: str, app_id: str, config: dict
) -> None:
role_dir = roles_dir / role_name
(role_dir / "vars").mkdir(parents=True, exist_ok=True)
(role_dir / "meta").mkdir(parents=True, exist_ok=True)
(role_dir / ROLE_FILE_VARS_MAIN).write_text(
dump_yaml_str({"application_id": app_id}),
encoding="utf-8",
)
domains_payload = config.get("domains", {}) if isinstance(config, dict) else {}
(role_dir / ROLE_FILE_META_DOMAINS).write_text(
dump_yaml_str(domains_payload),
encoding="utf-8",
)
def _run(self, argv: list[str]) -> tuple[int, str, str]:
out = io.StringIO()
err = io.StringIO()
with patch("sys.stdout", out), patch("sys.stderr", err):
try:
with patch("sys.argv", ["prog", *argv]):
mod.main()
return 0, out.getvalue(), err.getvalue()
except SystemExit as e:
code = int(e.code) if e.code is not None else 0
return code, out.getvalue(), err.getvalue()
def test_cli_supports_alias_and_www_flags(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
roles_dir = Path(tmp) / "roles"
roles_dir.mkdir()
self.write_role(
roles_dir,
"web-app-dashboard",
"web-app-dashboard",
{
"domains": {
"canonical": ["dashboard.{{ DOMAIN_PRIMARY }}"],
"aliases": ["alias.{{ DOMAIN_PRIMARY }}"],
}
},
)
with patch.object(mod.domain_list, "ROLES_DIR", roles_dir):
code, out, err = self._run(
[
"--domain-primary",
"infinito.test",
"--alias",
"--www",
]
)
self.assertEqual(code, 0)
self.assertEqual(err, "")
self.assertEqual(
out.strip().splitlines(),
[
"alias.infinito.test",
"dashboard.infinito.test",
"test.infinito.test",
"www.alias.infinito.test",
"www.dashboard.infinito.test",
"www.test.infinito.test",
],
)
if __name__ == "__main__":
main()