Files
computer-playbook/tests/unit/python/plugins/lookup/test_postgres_libraries.py
T
kevinveenbirkenbach 30417d2515 fix(svc-db-postgres): build on the official multi-arch postgres 18 image
postgis/postgis publishes amd64 only, so every postgres consumer failed
on arm64. The official postgres image serves both architectures and
already ships the contrib extensions bloom, pg_trgm and unaccent.

PostGIS moves into the postgres_libraries registry and is installed from
PGDG (postgresql-18-postgis-3) only for a consumer that declares it as
an extension, which is mobilizon alone. apt update reads every source
list again, because the PostGIS package depends on GDAL from Debian
main, which a PGDG-only update left without an install candidate.

Postgres 18 keeps its cluster in /var/lib/postgresql/18/docker and its
entrypoint treats a volume at the former /var/lib/postgresql/data as an
old database, so the central and the dedicated data volume both mount at
/var/lib/postgresql. Existing 17 clusters are not migrated: their data
directory trips the entrypoint's old-data check and the container
refuses to start.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit f78ebe46a4)
2026-10-01 22:19:09 +02:00

85 lines
2.6 KiB
Python

"""Unit tests for ``plugins/lookup/postgres_libraries.py``."""
import importlib.util
import unittest
from ansible.errors import AnsibleError
from . import PROJECT_ROOT
def _load_module(rel_path: str, name: str):
path = PROJECT_ROOT / rel_path
spec = importlib.util.spec_from_file_location(name, str(path))
mod = importlib.util.module_from_spec(spec)
assert spec and spec.loader
spec.loader.exec_module(mod)
return mod
class PostgresLibrariesLookupTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.mod = _load_module(
"plugins/lookup/postgres_libraries.py",
"lookup_postgres_libraries",
)
def _run(self, terms):
lookup = self.mod.LookupModule()
return lookup.run(terms)
def test_zero_terms_raises(self):
with self.assertRaises(AnsibleError):
self._run([])
def test_two_terms_raises(self):
with self.assertRaises(AnsibleError):
self._run([["vector"], "extra"])
def test_non_list_first_term_raises(self):
with self.assertRaises(AnsibleError):
self._run(["vector"])
def test_empty_extension_list_returns_empty(self):
result = self._run([[]])
self.assertEqual(result, [[]])
def test_extension_in_registry_returns_recipe(self):
result = self._run([["vector"]])[0]
self.assertEqual(len(result), 1)
self.assertEqual(result[0]["extension"], "vector")
self.assertEqual(result[0]["name"], "pgvector")
self.assertEqual(result[0]["apt_package"], "pgvector")
def test_base_extensions_are_filtered_out(self):
result = self._run([["bloom", "pg_trgm", "unaccent"]])[0]
self.assertEqual(result, [])
def test_postgis_is_built_only_for_a_role_that_declares_it(self):
result = self._run([["bloom", "postgis"]])[0]
self.assertEqual(
[(r["extension"], r["apt_package"]) for r in result],
[("postgis", "postgis-3")],
)
def test_mixed_extensions_returns_only_non_base(self):
result = self._run([["bloom", "vector", "postgis"]])[0]
self.assertEqual(
[r["extension"] for r in result],
["vector", "postgis"],
)
def test_duplicates_are_deduplicated(self):
result = self._run([["vector", "vector"]])[0]
self.assertEqual(len(result), 1)
def test_blanks_are_skipped(self):
result = self._run([["", " ", "vector"]])[0]
self.assertEqual(len(result), 1)
self.assertEqual(result[0]["extension"], "vector")
if __name__ == "__main__":
unittest.main()