mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 10:59:59 +00:00
Every script a role ships now lives under `files/<language>/`, and the unit
suite is split the same way: `tests/unit/python/` beside new sibling trees for
the other languages. `tests/lint/filesystem/test_role_files_layout.py` keeps it
that way; directories whose shape is dictated from outside carry a `.nocheck`
naming the constraint (Docker build contexts, WordPress mu-plugins, the Joomla
extension, Odoo addons, Playwright suites, the `files/test/test.sh` harness
that `test-e2e-cli` resolves generically).
This cannot be applied in halves. Moving a file and repointing what names it
are the same change: 14 references resolve only at deploy time, so the tree is
green either before or after, never between.
Those 14 were found by static resolution over every reference class, not by the
test suite -- a full `make quality-high` was green while all of them were
broken:
* 7 `src:` values built from a role variable holding a bare filename
(svc-bkp-remote-2-local, decidim, espocrm, friendica, joomla, pixelfed x2).
The variable doubles as the destination name inside the container, so the
language segment belongs at the call site, not in the variable.
* `sys-service/tasks/04_base.yml` resolved every consumer's systemd script
through `first_found(..., errors='strict')` over `files/script.{sh,py}`.
18 roles ship exactly that and have no template fallback: the play would
have died on each.
* `sys-front-inj-javascript` fell back to `<role>/files/javascript.js`; the
interface now reads `files/javascript/javascript.js`.
* `sys-front-inj-logout/templates/head_sub.j2` built the cache-busting mtime
path through `path_absolute(... 'files', ...)`.
* 4 `ansible.builtin.script:` invocations naming a bare command
(pull.py, prune.sh, set_postgres_superuser_password.sh, ganesha-serve.sh).
* `dev-python/files/shell/install.sh` pointed at a sibling role's script.
Depth-dependent paths inside the moved trees were bumped accordingly: 59
`parents[N]` computations, 12 relative climbs, and the per-role recover CLI,
whose path `cli/administration/recover/recoverers.py` still assembled from the
pre-move location.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
193 lines
6.7 KiB
Python
193 lines
6.7 KiB
Python
import unittest
|
|
|
|
from ansible.errors import AnsibleError
|
|
|
|
import utils.domains.application_domain_index as _application_domain_index
|
|
|
|
|
|
class TestApplicationDomainIndex(unittest.TestCase):
|
|
def setUp(self):
|
|
self.applications = {
|
|
"web-app-a": {
|
|
"domains": {
|
|
"canonical": ["a.example"],
|
|
"aliases": ["www.a.example", "A.ALIAS.EXAMPLE"],
|
|
}
|
|
},
|
|
"web-app-b": {
|
|
"domains": {
|
|
"canonical": "b.example",
|
|
"aliases": [],
|
|
}
|
|
},
|
|
"web-app-c": {
|
|
"domains": {
|
|
"canonical": {"web": "c.example", "api": "api.c.example"},
|
|
"aliases": {"www": "www.c.example"},
|
|
}
|
|
},
|
|
"web-app-nested": {
|
|
"domains": {
|
|
"canonical": {
|
|
"web": ["nested.example", "NESTED2.example"],
|
|
"api": {"v1": "api.nested.example"},
|
|
},
|
|
"aliases": [
|
|
{"alt": "alt.nested.example"},
|
|
["ALT2.nested.example", {"deep": ["deep.nested.example"]}],
|
|
],
|
|
}
|
|
},
|
|
"web-app-no-server": {},
|
|
"web-app-server-not-dict": "nope",
|
|
"web-app-domains-not-dict": {"domains": "nope"},
|
|
}
|
|
|
|
def test_iter_app_domains_empty_on_invalid_structure(self):
|
|
self.assertEqual(
|
|
list(
|
|
_application_domain_index.iter_app_domains(
|
|
self.applications["web-app-no-server"]
|
|
)
|
|
),
|
|
[],
|
|
)
|
|
self.assertEqual(
|
|
list(
|
|
_application_domain_index.iter_app_domains(
|
|
self.applications["web-app-server-not-dict"]
|
|
)
|
|
),
|
|
[],
|
|
)
|
|
self.assertEqual(
|
|
list(
|
|
_application_domain_index.iter_app_domains(
|
|
self.applications["web-app-domains-not-dict"]
|
|
)
|
|
),
|
|
[],
|
|
)
|
|
|
|
def test_iter_app_domains_flattens_all_supported_shapes(self):
|
|
got_a = list(
|
|
_application_domain_index.iter_app_domains(self.applications["web-app-a"])
|
|
)
|
|
self.assertEqual(
|
|
got_a,
|
|
["a.example", "www.a.example", "A.ALIAS.EXAMPLE"],
|
|
)
|
|
|
|
got_b = list(
|
|
_application_domain_index.iter_app_domains(self.applications["web-app-b"])
|
|
)
|
|
self.assertEqual(got_b, ["b.example"])
|
|
|
|
got_c = list(
|
|
_application_domain_index.iter_app_domains(self.applications["web-app-c"])
|
|
)
|
|
self.assertEqual(got_c, ["c.example", "api.c.example", "www.c.example"])
|
|
|
|
got_nested = list(
|
|
_application_domain_index.iter_app_domains(
|
|
self.applications["web-app-nested"]
|
|
)
|
|
)
|
|
self.assertEqual(
|
|
got_nested,
|
|
[
|
|
"nested.example",
|
|
"NESTED2.example",
|
|
"api.nested.example",
|
|
"alt.nested.example",
|
|
"ALT2.nested.example",
|
|
"deep.nested.example",
|
|
],
|
|
)
|
|
|
|
def test_build_domain_index_case_insensitive(self):
|
|
idx = _application_domain_index.build_domain_index(self.applications)
|
|
|
|
self.assertEqual(idx["a.example"], "web-app-a")
|
|
self.assertEqual(idx["www.a.example"], "web-app-a")
|
|
self.assertEqual(idx["a.alias.example"], "web-app-a")
|
|
self.assertEqual(idx["b.example"], "web-app-b")
|
|
self.assertEqual(idx["c.example"], "web-app-c")
|
|
self.assertEqual(idx["api.c.example"], "web-app-c")
|
|
self.assertEqual(idx["www.c.example"], "web-app-c")
|
|
self.assertEqual(idx["nested.example"], "web-app-nested")
|
|
self.assertEqual(idx["nested2.example"], "web-app-nested")
|
|
self.assertEqual(idx["api.nested.example"], "web-app-nested")
|
|
self.assertEqual(idx["alt.nested.example"], "web-app-nested")
|
|
self.assertEqual(idx["alt2.nested.example"], "web-app-nested")
|
|
self.assertEqual(idx["deep.nested.example"], "web-app-nested")
|
|
|
|
def test_build_domain_index_type_check(self):
|
|
with self.assertRaises(AnsibleError):
|
|
_application_domain_index.build_domain_index("nope") # type: ignore[arg-type]
|
|
|
|
def test_build_domain_index_detects_collision_case_insensitive(self):
|
|
apps = {
|
|
"app1": {"domains": {"canonical": ["X.EXAMPLE"], "aliases": []}},
|
|
"app2": {"domains": {"canonical": ["x.example"], "aliases": []}},
|
|
}
|
|
with self.assertRaises(AnsibleError) as ctx:
|
|
_application_domain_index.build_domain_index(apps)
|
|
self.assertIn("domain collision", str(ctx.exception).lower())
|
|
|
|
def test_resolve_app_id_for_domain_found(self):
|
|
self.assertEqual(
|
|
_application_domain_index.resolve_app_id_for_domain(
|
|
self.applications, "a.example"
|
|
),
|
|
"web-app-a",
|
|
)
|
|
self.assertEqual(
|
|
_application_domain_index.resolve_app_id_for_domain(
|
|
self.applications, "WWW.A.EXAMPLE"
|
|
),
|
|
"web-app-a",
|
|
)
|
|
self.assertEqual(
|
|
_application_domain_index.resolve_app_id_for_domain(
|
|
self.applications, "api.c.example"
|
|
),
|
|
"web-app-c",
|
|
)
|
|
self.assertEqual(
|
|
_application_domain_index.resolve_app_id_for_domain(
|
|
self.applications, "DEEP.NESTED.EXAMPLE"
|
|
),
|
|
"web-app-nested",
|
|
)
|
|
|
|
def test_resolve_app_id_for_domain_not_found_or_empty(self):
|
|
self.assertIsNone(
|
|
_application_domain_index.resolve_app_id_for_domain(
|
|
self.applications, "missing.example"
|
|
)
|
|
)
|
|
self.assertIsNone(
|
|
_application_domain_index.resolve_app_id_for_domain(self.applications, "")
|
|
)
|
|
self.assertIsNone(
|
|
_application_domain_index.resolve_app_id_for_domain(
|
|
self.applications, " "
|
|
)
|
|
)
|
|
self.assertIsNone(
|
|
_application_domain_index.resolve_app_id_for_domain(self.applications, None) # type: ignore[arg-type]
|
|
)
|
|
|
|
def test_resolve_app_id_for_domain_raises_on_collision(self):
|
|
apps = {
|
|
"app1": {"domains": {"canonical": ["x.example"], "aliases": []}},
|
|
"app2": {"domains": {"canonical": ["X.EXAMPLE"], "aliases": []}},
|
|
}
|
|
with self.assertRaises(AnsibleError):
|
|
_application_domain_index.resolve_app_id_for_domain(apps, "x.example")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|