mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-07 13:32:57 +00:00
## Problem Ref https://neondb.slack.com/archives/C036U0GRMRB/p1688122168477729 ## Summary of changes - Add sha from postgres repo into postgres version string (via `--with-extra-version`) - Add a test that Postgres version matches the expected one - Remove build-time hard check and allow only related tests to fail
36 lines
1.5 KiB
Python
36 lines
1.5 KiB
Python
import json
|
|
import re
|
|
from pathlib import Path
|
|
|
|
from fixtures.neon_fixtures import PgBin
|
|
from fixtures.pg_version import PgVersion
|
|
|
|
|
|
def test_postgres_version(base_dir: Path, pg_bin: PgBin, pg_version: PgVersion):
|
|
"""Test that Postgres version matches the one we expect"""
|
|
|
|
with (base_dir / "vendor" / "revisions.json").open() as f:
|
|
expected_revisions = json.load(f)
|
|
|
|
output_prefix = pg_bin.run_capture(["postgres", "--version"], with_command_header=False)
|
|
stdout = Path(f"{output_prefix}.stdout")
|
|
assert stdout.exists(), "postgres --version didn't print anything to stdout"
|
|
|
|
with stdout.open() as f:
|
|
output = f.read().strip()
|
|
|
|
# `postgres --version` prints something like "postgres (PostgreSQL) 15.6 (85d809c124a898847a97d66a211f7d5ef4f8e0cb)".
|
|
pattern = r"postgres \(PostgreSQL\) (?P<version>\d+\.\d+) \((?P<commit>[0-9a-f]{40})\)"
|
|
match = re.search(pattern, output, re.IGNORECASE)
|
|
assert match is not None, f"Can't parse {output} with {pattern}"
|
|
|
|
version = match.group("version")
|
|
commit = match.group("commit")
|
|
|
|
assert (
|
|
pg_version.v_prefixed in expected_revisions
|
|
), f"Version `{pg_version.v_prefixed}` doesn't exist in `vendor/revisions.json`, please update it if these changes are intentional"
|
|
|
|
msg = f"Unexpected Postgres {pg_version} version: `{output}`, please update `vendor/revisions.json` if these changes are intentional"
|
|
assert [version, commit] == expected_revisions[pg_version.v_prefixed], msg
|