-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial readiness assessment integration tests
- Loading branch information
1 parent
5f08873
commit d5e67e2
Showing
5 changed files
with
240 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
ARG PG_VERSION | ||
|
||
# Use the official PostgreSQL image as a base | ||
FROM postgres:$PG_VERSION | ||
|
||
ARG PG_VERSION | ||
# Install pglogical dependencies and pglogical itself | ||
RUN apt-get update && apt-get install -y \ | ||
postgresql-$PG_VERSION-pglogical \ | ||
&& apt-get autoremove -y \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Expose the default PostgreSQL port | ||
EXPOSE 5432 | ||
|
||
# Set the default command to start PostgreSQL | ||
CMD ["postgres"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
services: | ||
postgres12: | ||
networks: | ||
- default | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
args: | ||
PG_VERSION: 12 | ||
ports: | ||
- "${POSTGRES12_PORT:-5423}:5432" # use a non-standard port here | ||
environment: | ||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-super-secret} | ||
command: | ||
- "postgres" | ||
- "-c" | ||
- "WAL_LEVEL=LOGICAL" | ||
- "-c" | ||
- "shared_preload_libraries=pglogical" | ||
postgres13: | ||
networks: | ||
- default | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
args: | ||
PG_VERSION: 13 | ||
ports: | ||
- "${POSTGRES13_PORT:-5424}:5432" # use a non-standard port here | ||
environment: | ||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-super-secret} | ||
command: | ||
- "postgres" | ||
- "-c" | ||
- "WAL_LEVEL=LOGICAL" | ||
- "-c" | ||
- "shared_preload_libraries=pglogical" | ||
postgres14: | ||
networks: | ||
- default | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
args: | ||
PG_VERSION: 14 | ||
ports: | ||
- "${POSTGRES14_PORT:-5425}:5432" # use a non-standard port here | ||
environment: | ||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-super-secret} | ||
command: | ||
- "postgres" | ||
- "-c" | ||
- "WAL_LEVEL=LOGICAL" | ||
- "-c" | ||
- "shared_preload_libraries=pglogical" | ||
postgres15: | ||
networks: | ||
- default | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
args: | ||
PG_VERSION: 15 | ||
ports: | ||
- "${POSTGRES15_PORT:-5426}:5432" # use a non-standard port here | ||
environment: | ||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-super-secret} | ||
command: | ||
- "postgres" | ||
- "-c" | ||
- "WAL_LEVEL=LOGICAL" | ||
- "-c" | ||
- "shared_preload_libraries=pglogical" | ||
postgres16: | ||
networks: | ||
- default | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
args: | ||
PG_VERSION: 16 | ||
ports: | ||
- "${POSTGRES16_PORT:-5427}:5432" # use a non-standard port here | ||
environment: | ||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-super-secret} | ||
command: | ||
- "postgres" | ||
- "-c" | ||
- "WAL_LEVEL=LOGICAL" | ||
- "-c" | ||
- "shared_preload_libraries=pglogical" | ||
postgres17: | ||
networks: | ||
- default | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
args: | ||
PG_VERSION: 17 | ||
ports: | ||
- "${POSTGRES17_PORT:-5428}:5432" # use a non-standard port here | ||
environment: | ||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-super-secret} | ||
command: | ||
- "postgres" | ||
- "-c" | ||
- "WAL_LEVEL=LOGICAL" | ||
- "-c" | ||
- "shared_preload_libraries=pglogical" | ||
networks: | ||
default: | ||
driver: bridge |
105 changes: 105 additions & 0 deletions
105
tests/integration/postgres/test_readiness_assessment.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Integration tests for the CLI.""" | ||
|
||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
from textwrap import dedent | ||
from typing import TYPE_CHECKING | ||
from urllib.parse import urlparse | ||
|
||
import pytest | ||
from sqlalchemy import text | ||
|
||
from dma.cli.main import app | ||
from dma.lib.db.local import get_duckdb_connection | ||
|
||
if TYPE_CHECKING: | ||
from click.testing import CliRunner | ||
from sqlalchemy import Engine | ||
|
||
pytestmark = [ | ||
pytest.mark.anyio, | ||
pytest.mark.postgres, | ||
pytest.mark.xdist_group("postgres"), | ||
] | ||
|
||
|
||
def test_pglogical( | ||
sync_engine: Engine, | ||
runner: CliRunner, | ||
) -> None: | ||
with sync_engine.begin() as conn: | ||
conn.execute(text(dedent("""create extension if not exists pglogical;"""))) | ||
url = urlparse(str(sync_engine.url.render_as_string(hide_password=False))) | ||
result = runner.invoke( | ||
app, | ||
[ | ||
"readiness-check", | ||
"--db-type", | ||
"postgres", | ||
"--no-prompt", | ||
"--hostname", | ||
f"{url.hostname}", | ||
"--port", | ||
f"{url.port!s}", | ||
"--database", | ||
f"{url.path.lstrip('/')}", | ||
"--username", | ||
f"{url.username}", | ||
"--password", | ||
f"{url.password}", | ||
], | ||
) | ||
assert result.exit_code == 0 | ||
with get_duckdb_connection(Path("tmp/")) as local_db: | ||
rows = local_db.sql( | ||
"select severity from readiness_check_summary WHERE rule_code = 'PGLOGICAL_INSTALLED'", | ||
).fetchall() | ||
for row in rows: | ||
assert row[0] == "PASS" | ||
|
||
|
||
def test_wal_level( | ||
sync_engine: Engine, | ||
runner: CliRunner, | ||
) -> None: | ||
url = urlparse(str(sync_engine.url.render_as_string(hide_password=False))) | ||
result = runner.invoke( | ||
app, | ||
[ | ||
"readiness-check", | ||
"--db-type", | ||
"postgres", | ||
"--no-prompt", | ||
"--hostname", | ||
f"{url.hostname}", | ||
"--port", | ||
f"{url.port!s}", | ||
"--database", | ||
f"{url.path.lstrip('/')}", | ||
"--username", | ||
f"{url.username}", | ||
"--password", | ||
f"{url.password}", | ||
], | ||
) | ||
assert result.exit_code == 0 | ||
with get_duckdb_connection(Path("tmp/")) as local_db: | ||
rows = local_db.sql( | ||
"select severity from readiness_check_summary WHERE rule_code = 'WAL_LEVEL'", | ||
).fetchall() | ||
for row in rows: | ||
assert row[0] == "PASS" |