-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Log based testing, upgrade to postgres16 for testing (#316)
Setup allowing pytest for log_based syncs Closes #294 --------- Co-authored-by: Edgar Ramírez Mondragón <[email protected]> Co-authored-by: Derek Visch <[email protected]>
- Loading branch information
1 parent
2eddf32
commit acaca95
Showing
7 changed files
with
99 additions
and
7 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,9 +28,12 @@ jobs: | |
sudo chown 999:999 ssl/server.key | ||
chmod 600 ssl/pkey.key | ||
- name: Set up Postgres container | ||
- name: Build Postgres container | ||
run: | | ||
docker compose -f docker-compose.yml up -d | ||
docker build . --tag meltano/log_based | ||
- name: Compose Postgres container | ||
run: | | ||
docker compose -f docker-compose.yml up -d --wait --wait-timeout=30 | ||
- uses: isbang/[email protected] | ||
|
||
|
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,12 @@ | ||
FROM postgres:16 | ||
|
||
RUN apt-get update | ||
RUN apt-mark hold locales | ||
RUN apt-get install curl ca-certificates -y | ||
RUN install -d /usr/share/postgresql-common/pgdg | ||
RUN curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc | ||
RUN sh -c 'echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] https://apt.postgresql.org/pub/repos/apt bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list' | ||
RUN apt-get update | ||
RUN apt-get install postgresql-server-dev-16 -y | ||
RUN sh -c 'export PATH=/usr/lib/postgresql/16/bin:$PATH' | ||
RUN apt-get install postgresql-16-wal2json -y |
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 @@ | ||
SELECT * FROM pg_create_logical_replication_slot('tappostgres', 'wal2json'); |
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
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,59 @@ | ||
import json | ||
|
||
import sqlalchemy | ||
from sqlalchemy import Column, MetaData, Table | ||
from sqlalchemy.dialects.postgresql import BIGINT, TEXT | ||
from tap_postgres.tap import TapPostgres | ||
from tests.test_core import PostgresTestRunner | ||
|
||
|
||
LOG_BASED_CONFIG = { | ||
"host": "localhost", | ||
"port": 5434, | ||
"user": "postgres", | ||
"password": "postgres", | ||
"database": "postgres", | ||
} | ||
|
||
def test_null_append(): | ||
"""LOG_BASED syncs failed with string property types. (issue #294). | ||
This test checks that even when a catalog contains properties with types represented | ||
as strings (ex: "object") instead of arrays (ex: ["object"] or ["object", "null"]), | ||
LOG_BASED replication can still append the "null" option to a property's type. | ||
""" | ||
table_name = "test_null_append" | ||
engine = sqlalchemy.create_engine("postgresql://postgres:postgres@localhost:5434/postgres") | ||
|
||
metadata_obj = MetaData() | ||
table = Table( | ||
table_name, | ||
metadata_obj, | ||
Column("id", BIGINT, primary_key = True), | ||
Column("data", TEXT, nullable = True) | ||
) | ||
with engine.connect() as conn: | ||
table.drop(conn, checkfirst=True) | ||
metadata_obj.create_all(conn) | ||
insert = table.insert().values(id=123, data="hello world") | ||
conn.execute(insert) | ||
tap = TapPostgres(config=LOG_BASED_CONFIG) | ||
tap_catalog = json.loads(tap.catalog_json_text) | ||
altered_table_name = f"public-{table_name}" | ||
for stream in tap_catalog["streams"]: | ||
if stream.get("stream") and altered_table_name not in stream["stream"]: | ||
for metadata in stream["metadata"]: | ||
metadata["metadata"]["selected"] = False | ||
else: | ||
stream["replication_method"] = "LOG_BASED" | ||
stream["replication_key"] = "_sdc_lsn" | ||
stream["schema"]["properties"]["data"]["type"] = "string" | ||
for metadata in stream["metadata"]: | ||
metadata["metadata"]["selected"] = True | ||
if metadata["breadcrumb"] == []: | ||
metadata["metadata"]["replication-method"] = "LOG_BASED" | ||
|
||
test_runner = PostgresTestRunner( | ||
tap_class=TapPostgres, config=LOG_BASED_CONFIG, catalog=tap_catalog | ||
) | ||
test_runner.sync_all() |