Better integration test.
This commit is contained in:
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@@ -1,5 +1,5 @@
|
|||||||
name: CI
|
name: CI
|
||||||
|
run-name: "Test on master branch"
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [ master ]
|
||||||
|
|||||||
66
.github/workflows/integration-tests.yml
vendored
66
.github/workflows/integration-tests.yml
vendored
@@ -1,5 +1,5 @@
|
|||||||
name: Integration Tests
|
name: Integration Tests
|
||||||
|
run-name: "Integration Tests"
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [ master ]
|
||||||
@@ -11,6 +11,21 @@ jobs:
|
|||||||
name: Integration Tests
|
name: Integration Tests
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres:16-alpine
|
||||||
|
env:
|
||||||
|
POSTGRES_USER: relspec
|
||||||
|
POSTGRES_PASSWORD: relspec_test_password
|
||||||
|
POSTGRES_DB: relspec_test
|
||||||
|
ports:
|
||||||
|
- 5439:5432
|
||||||
|
options: >-
|
||||||
|
--health-cmd pg_isready
|
||||||
|
--health-interval 10s
|
||||||
|
--health-timeout 5s
|
||||||
|
--health-retries 5
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -31,41 +46,18 @@ jobs:
|
|||||||
- name: Download dependencies
|
- name: Download dependencies
|
||||||
run: go mod download
|
run: go mod download
|
||||||
|
|
||||||
- name: Start PostgreSQL container
|
|
||||||
run: |
|
|
||||||
docker run -d \
|
|
||||||
--name relspec-test-postgres \
|
|
||||||
--network host \
|
|
||||||
-e POSTGRES_USER=relspec \
|
|
||||||
-e POSTGRES_PASSWORD=relspec_test_password \
|
|
||||||
-e POSTGRES_DB=relspec_test \
|
|
||||||
postgres:16-alpine
|
|
||||||
|
|
||||||
- name: Wait for PostgreSQL to be ready
|
|
||||||
run: |
|
|
||||||
echo "Waiting for PostgreSQL to start..."
|
|
||||||
for i in {1..30}; do
|
|
||||||
if docker exec relspec-test-postgres pg_isready -U relspec -d relspec_test > /dev/null 2>&1; then
|
|
||||||
echo "PostgreSQL is ready!"
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
echo "Waiting... ($i/30)"
|
|
||||||
sleep 1
|
|
||||||
done
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
- name: Copy init script into container
|
|
||||||
run: |
|
|
||||||
docker cp tests/postgres/init.sql relspec-test-postgres:/tmp/init.sql
|
|
||||||
|
|
||||||
- name: Initialize test database
|
- name: Initialize test database
|
||||||
|
env:
|
||||||
|
PGPASSWORD: relspec_test_password
|
||||||
run: |
|
run: |
|
||||||
docker exec relspec-test-postgres psql -U relspec -d relspec_test -f /tmp/init.sql
|
psql -h localhost -U relspec -d relspec_test -f tests/postgres/init.sql
|
||||||
|
|
||||||
- name: Verify database setup
|
- name: Verify database setup
|
||||||
|
env:
|
||||||
|
PGPASSWORD: relspec_test_password
|
||||||
run: |
|
run: |
|
||||||
echo "Verifying database initialization..."
|
echo "Verifying database initialization..."
|
||||||
docker exec relspec-test-postgres psql -U relspec -d relspec_test -c "
|
psql -h localhost -U relspec -d relspec_test -c "
|
||||||
SELECT
|
SELECT
|
||||||
(SELECT COUNT(*) FROM pg_namespace WHERE nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast') AND nspname NOT LIKE 'pg_%') as schemas,
|
(SELECT COUNT(*) FROM pg_namespace WHERE nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast') AND nspname NOT LIKE 'pg_%') as schemas,
|
||||||
(SELECT COUNT(*) FROM pg_tables WHERE schemaname NOT IN ('pg_catalog', 'information_schema')) as tables,
|
(SELECT COUNT(*) FROM pg_tables WHERE schemaname NOT IN ('pg_catalog', 'information_schema')) as tables,
|
||||||
@@ -75,17 +67,5 @@ jobs:
|
|||||||
|
|
||||||
- name: Run integration tests
|
- name: Run integration tests
|
||||||
env:
|
env:
|
||||||
RELSPEC_TEST_PG_CONN: postgres://relspec:relspec_test_password@localhost:5432/relspec_test
|
RELSPEC_TEST_PG_CONN: postgres://relspec:relspec_test_password@localhost:5439/relspec_test
|
||||||
run: make test-integration
|
run: make test-integration
|
||||||
|
|
||||||
- name: Stop PostgreSQL container
|
|
||||||
if: always()
|
|
||||||
run: |
|
|
||||||
docker stop relspec-test-postgres || true
|
|
||||||
docker rm relspec-test-postgres || true
|
|
||||||
|
|
||||||
- name: Summary
|
|
||||||
if: always()
|
|
||||||
run: |
|
|
||||||
echo "Integration tests completed."
|
|
||||||
echo "PostgreSQL container has been cleaned up."
|
|
||||||
|
|||||||
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -1,5 +1,5 @@
|
|||||||
name: Release
|
name: Release
|
||||||
|
run-name: "Making Release"
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
|
|||||||
10
Makefile
10
Makefile
@@ -52,7 +52,7 @@ test-integration: ## Run integration tests (requires RELSPEC_TEST_PG_CONN enviro
|
|||||||
@echo "Running integration tests..."
|
@echo "Running integration tests..."
|
||||||
@if [ -z "$$RELSPEC_TEST_PG_CONN" ]; then \
|
@if [ -z "$$RELSPEC_TEST_PG_CONN" ]; then \
|
||||||
echo "Error: RELSPEC_TEST_PG_CONN environment variable is not set"; \
|
echo "Error: RELSPEC_TEST_PG_CONN environment variable is not set"; \
|
||||||
echo "Example: export RELSPEC_TEST_PG_CONN='postgres://relspec:relspec_test_password@localhost:5432/relspec_test'"; \
|
echo "Example: export RELSPEC_TEST_PG_CONN='postgres://relspec:relspec_test_password@localhost:5439/relspec_test'"; \
|
||||||
exit 1; \
|
exit 1; \
|
||||||
fi
|
fi
|
||||||
@echo "Running PostgreSQL reader tests..."
|
@echo "Running PostgreSQL reader tests..."
|
||||||
@@ -116,7 +116,7 @@ docker-up: ## Start PostgreSQL test database
|
|||||||
-e POSTGRES_USER=relspec \
|
-e POSTGRES_USER=relspec \
|
||||||
-e POSTGRES_PASSWORD=relspec_test_password \
|
-e POSTGRES_PASSWORD=relspec_test_password \
|
||||||
-e POSTGRES_DB=relspec_test \
|
-e POSTGRES_DB=relspec_test \
|
||||||
-p 5433:5432 \
|
-p 5439:5432 \
|
||||||
-v ./tests/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql:Z \
|
-v ./tests/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql:Z \
|
||||||
postgres:16-alpine 2>/dev/null || echo "Container already running"; \
|
postgres:16-alpine 2>/dev/null || echo "Container already running"; \
|
||||||
else \
|
else \
|
||||||
@@ -124,8 +124,8 @@ docker-up: ## Start PostgreSQL test database
|
|||||||
fi
|
fi
|
||||||
@echo "Waiting for PostgreSQL to be ready..."
|
@echo "Waiting for PostgreSQL to be ready..."
|
||||||
@sleep 3
|
@sleep 3
|
||||||
@echo "PostgreSQL is running on port 5433"
|
@echo "PostgreSQL is running on port 5439"
|
||||||
@echo "Connection: postgres://relspec:relspec_test_password@localhost:5433/relspec_test"
|
@echo "Connection: postgres://relspec:relspec_test_password@localhost:5439/relspec_test"
|
||||||
|
|
||||||
docker-down: ## Stop PostgreSQL test database
|
docker-down: ## Stop PostgreSQL test database
|
||||||
@echo "Stopping PostgreSQL test database (using $(CONTAINER_RUNTIME))..."
|
@echo "Stopping PostgreSQL test database (using $(CONTAINER_RUNTIME))..."
|
||||||
@@ -147,7 +147,7 @@ docker-test: ## Run PostgreSQL integration tests with Docker/Podman
|
|||||||
docker-test-integration: docker-up ## Start DB and run integration tests
|
docker-test-integration: docker-up ## Start DB and run integration tests
|
||||||
@echo "Running integration tests..."
|
@echo "Running integration tests..."
|
||||||
@sleep 2
|
@sleep 2
|
||||||
@RELSPEC_TEST_PG_CONN="postgres://relspec:relspec_test_password@localhost:5433/relspec_test" \
|
@RELSPEC_TEST_PG_CONN="postgres://relspec:relspec_test_password@localhost:5439/relspec_test" \
|
||||||
$(GOTEST) -v ./pkg/readers/pgsql/ -count=1 || (make docker-down && exit 1)
|
$(GOTEST) -v ./pkg/readers/pgsql/ -count=1 || (make docker-down && exit 1)
|
||||||
@make docker-down
|
@make docker-down
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ services:
|
|||||||
POSTGRES_PASSWORD: relspec_test_password
|
POSTGRES_PASSWORD: relspec_test_password
|
||||||
POSTGRES_DB: relspec_test
|
POSTGRES_DB: relspec_test
|
||||||
ports:
|
ports:
|
||||||
- "5433:5432" # Using 5433 to avoid conflicts with local PostgreSQL
|
- "5439:5432" # Using 5439 to avoid conflicts with local PostgreSQL
|
||||||
volumes:
|
volumes:
|
||||||
- ./tests/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql
|
- ./tests/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql
|
||||||
- postgres_data:/var/lib/postgresql/data
|
- postgres_data:/var/lib/postgresql/data
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ SELECT
|
|||||||
"
|
"
|
||||||
|
|
||||||
# Set environment variable for tests
|
# Set environment variable for tests
|
||||||
export RELSPEC_TEST_PG_CONN="postgres://relspec:relspec_test_password@localhost:5433/relspec_test"
|
export RELSPEC_TEST_PG_CONN="postgres://relspec:relspec_test_password@localhost:5439/relspec_test"
|
||||||
|
|
||||||
echo -e "\n${YELLOW}Running PostgreSQL reader tests...${NC}"
|
echo -e "\n${YELLOW}Running PostgreSQL reader tests...${NC}"
|
||||||
echo "Connection string: $RELSPEC_TEST_PG_CONN"
|
echo "Connection string: $RELSPEC_TEST_PG_CONN"
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ CONTAINER_NAME="relspec-test-postgres"
|
|||||||
POSTGRES_USER="relspec"
|
POSTGRES_USER="relspec"
|
||||||
POSTGRES_PASSWORD="relspec_test_password"
|
POSTGRES_PASSWORD="relspec_test_password"
|
||||||
POSTGRES_DB="relspec_test"
|
POSTGRES_DB="relspec_test"
|
||||||
POSTGRES_PORT="5433"
|
POSTGRES_PORT="5439"
|
||||||
|
|
||||||
# Check if podman is available
|
# Check if podman is available
|
||||||
if ! command -v podman &> /dev/null; then
|
if ! command -v podman &> /dev/null; then
|
||||||
|
|||||||
Reference in New Issue
Block a user