Skip to content

Commit

Permalink
source-redshift-batch: Test against Postgres in CI
Browse files Browse the repository at this point in the history
Redshift is kind of PostgreSQL and kind of not (for instance,
Redshift has a completely different columnar storage engine and
doesn't expose an XMIN system column), but it's close enough that
our test suite passes when run against Postgres.

Since it's tricky to test against Redshift in CI builds, we might
as well do the next-best thing and test against a local Postgres
instance since practically speaking the alternative is no CI tests
at all.
  • Loading branch information
willdonnelly committed Feb 20, 2025
1 parent 6490f6f commit 6c26ace
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ jobs:
"source-mysql-batch",
"source-postgres",
"source-postgres-batch",
"source-redshift-batch",
"source-sftp",
"source-sqlserver",
"source-mongodb"
Expand Down
4 changes: 3 additions & 1 deletion source-redshift-batch/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ RUN go install -v github.com/jackc/pgx/v5

# Run tests and build the connector
COPY source-redshift-batch ./source-redshift-batch
RUN go test -v ./source-redshift-batch/...
ARG TEST_DATABASE=yes
ENV TEST_DATABASE=$TEST_DATABASE
RUN go test -short -failfast -v ./source-redshift-batch/...
RUN go build -o ./connector -v ./source-redshift-batch/...

# Runtime Stage
Expand Down
30 changes: 30 additions & 0 deletions source-redshift-batch/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
services:
db:
image: 'postgres:latest'
command: [ "postgres" ]
ports:
- "5432:5432"
environment:
{
"POSTGRES_DB": "postgres",
"POSTGRES_USER": "postgres",
"POSTGRES_PASSWORD": "postgres"
}
healthcheck:
test: "true"
interval: 3s
networks:
- flow-test
volumes:
- type: bind
source: ./docker-initdb.sh
target: /docker-entrypoint-initdb.d/init-user-db.sh
- postgres_data:/var/lib/postgresql/data

networks:
flow-test:
name: flow-test
external: true

volumes:
postgres_data: {}
15 changes: 15 additions & 0 deletions source-redshift-batch/docker-initdb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -e

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE USER flow_capture WITH PASSWORD 'secret1234' REPLICATION;
CREATE SCHEMA IF NOT EXISTS test;
GRANT USAGE ON SCHEMA test TO flow_capture;
ALTER DEFAULT PRIVILEGES IN SCHEMA test GRANT SELECT ON TABLES to flow_capture;
GRANT SELECT ON ALL TABLES IN SCHEMA test TO flow_capture;
GRANT CREATE, USAGE ON SCHEMA public TO flow_capture;
CREATE EXTENSION IF NOT EXISTS citext;
EOSQL
8 changes: 4 additions & 4 deletions source-redshift-batch/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ import (
)

var (
dbAddress = flag.String("db_address", "default-workgroup.123456789012.us-east-1.redshift-serverless.amazonaws.com:5439", "The database server address to use for tests")
dbName = flag.String("db_name", "dev", "Use the named database for tests")
dbAddress = flag.String("db_address", "localhost:5432", "The database server address to use for tests")
dbName = flag.String("db_name", "postgres", "Use the named database for tests")
dbControlUser = flag.String("db_control_user", "postgres", "The user for test setup/control operations")
dbControlPass = flag.String("db_control_pass", "postgres", "The password the the test setup/control user")
dbCaptureUser = flag.String("db_capture_user", "flow_capture", "The user to perform captures as")
dbCapturePass = flag.String("db_capture_pass", "secret1234", "The password for the capture user")
dbControlUser = flag.String("db_control_user", "", "The user for test setup/control operations, if different from the capture user")
dbControlPass = flag.String("db_control_pass", "", "The password the the test setup/control user, if different from the capture password")
)

func TestMain(m *testing.M) {
Expand Down

0 comments on commit 6c26ace

Please sign in to comment.