Skip to content

Commit 80d4113

Browse files
authored
Merge pull request #41 from gadget-inc/integration-tests
Add postgres integration tests
2 parents 9853fe3 + ae6101c commit 80d4113

3 files changed

Lines changed: 1203 additions & 4 deletions

File tree

.github/workflows/test.yml

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ on:
77
branches: [ main ]
88

99
jobs:
10-
test:
10+
unit-test:
11+
name: Unit Tests
1112
runs-on: ubuntu-latest
1213

1314
steps:
@@ -29,8 +30,67 @@ jobs:
2930
- name: Download dependencies
3031
run: go mod download
3132

32-
- name: Run tests
33+
- name: Run unit tests
3334
run: go test -v ./...
3435

35-
- name: Run tests with race detection
36+
- name: Run unit tests with race detection
3637
run: go test -race -v ./...
38+
39+
integration-test:
40+
name: Integration Tests
41+
runs-on: ubuntu-latest
42+
43+
steps:
44+
- uses: actions/checkout@v4
45+
46+
- name: Set up Go
47+
uses: actions/setup-go@v4
48+
with:
49+
go-version: '1.22.3'
50+
51+
- name: Cache Go modules
52+
uses: actions/cache@v3
53+
with:
54+
path: ~/go/pkg/mod
55+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
56+
restore-keys: |
57+
${{ runner.os }}-go-
58+
59+
- name: Download dependencies
60+
run: go mod download
61+
62+
- name: Start PostgreSQL with logical replication
63+
run: |
64+
docker run -d \
65+
--name postgres-test \
66+
-e POSTGRES_USER=postgres \
67+
-e POSTGRES_PASSWORD=postgres \
68+
-e POSTGRES_DB=postgres \
69+
-p 5432:5432 \
70+
postgres:17 \
71+
-c wal_level=logical \
72+
-c max_wal_senders=10 \
73+
-c max_replication_slots=10
74+
75+
- name: Wait for PostgreSQL to be ready
76+
run: |
77+
for i in {1..30}; do
78+
docker exec postgres-test pg_isready -U postgres && break
79+
echo "Waiting for PostgreSQL..."
80+
sleep 2
81+
done
82+
83+
- name: Verify PostgreSQL configuration
84+
run: |
85+
docker exec postgres-test psql -U postgres -c "SHOW wal_level;"
86+
docker exec postgres-test psql -U postgres -c "SHOW max_replication_slots;"
87+
docker exec postgres-test psql -U postgres -c "SHOW max_wal_senders;"
88+
89+
- name: Run integration tests
90+
env:
91+
POSTGRES_HOST: localhost
92+
POSTGRES_PORT: 5432
93+
POSTGRES_USER: postgres
94+
POSTGRES_PASSWORD: postgres
95+
POSTGRES_DB: postgres
96+
run: go test -v -tags=integration -timeout=300s ./listener/...

docker/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ volumes:
55

66
x-postgres-common:
77
&postgres-common
8-
image: postgres:14-alpine
8+
image: postgres:17-alpine
99
user: postgres
1010
restart: always
1111
healthcheck:

0 commit comments

Comments
 (0)