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
|
||||
|
||||
run-name: "Test on master branch"
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
|
||||
66
.github/workflows/integration-tests.yml
vendored
66
.github/workflows/integration-tests.yml
vendored
@@ -1,5 +1,5 @@
|
||||
name: Integration Tests
|
||||
|
||||
run-name: "Integration Tests"
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
@@ -11,6 +11,21 @@ jobs:
|
||||
name: Integration Tests
|
||||
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:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
@@ -31,41 +46,18 @@ jobs:
|
||||
- name: Download dependencies
|
||||
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
|
||||
env:
|
||||
PGPASSWORD: relspec_test_password
|
||||
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
|
||||
env:
|
||||
PGPASSWORD: relspec_test_password
|
||||
run: |
|
||||
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 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,
|
||||
@@ -75,17 +67,5 @@ jobs:
|
||||
|
||||
- name: Run integration tests
|
||||
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
|
||||
|
||||
- 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
|
||||
|
||||
run-name: "Making Release"
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
|
||||
10
Makefile
10
Makefile
@@ -52,7 +52,7 @@ test-integration: ## Run integration tests (requires RELSPEC_TEST_PG_CONN enviro
|
||||
@echo "Running integration tests..."
|
||||
@if [ -z "$$RELSPEC_TEST_PG_CONN" ]; then \
|
||||
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; \
|
||||
fi
|
||||
@echo "Running PostgreSQL reader tests..."
|
||||
@@ -116,7 +116,7 @@ docker-up: ## Start PostgreSQL test database
|
||||
-e POSTGRES_USER=relspec \
|
||||
-e POSTGRES_PASSWORD=relspec_test_password \
|
||||
-e POSTGRES_DB=relspec_test \
|
||||
-p 5433:5432 \
|
||||
-p 5439:5432 \
|
||||
-v ./tests/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql:Z \
|
||||
postgres:16-alpine 2>/dev/null || echo "Container already running"; \
|
||||
else \
|
||||
@@ -124,8 +124,8 @@ docker-up: ## Start PostgreSQL test database
|
||||
fi
|
||||
@echo "Waiting for PostgreSQL to be ready..."
|
||||
@sleep 3
|
||||
@echo "PostgreSQL is running on port 5433"
|
||||
@echo "Connection: postgres://relspec:relspec_test_password@localhost:5433/relspec_test"
|
||||
@echo "PostgreSQL is running on port 5439"
|
||||
@echo "Connection: postgres://relspec:relspec_test_password@localhost:5439/relspec_test"
|
||||
|
||||
docker-down: ## Stop PostgreSQL test database
|
||||
@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
|
||||
@echo "Running integration tests..."
|
||||
@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)
|
||||
@make docker-down
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ services:
|
||||
POSTGRES_PASSWORD: relspec_test_password
|
||||
POSTGRES_DB: relspec_test
|
||||
ports:
|
||||
- "5433:5432" # Using 5433 to avoid conflicts with local PostgreSQL
|
||||
- "5439:5432" # Using 5439 to avoid conflicts with local PostgreSQL
|
||||
volumes:
|
||||
- ./tests/postgres/init.sql:/docker-entrypoint-initdb.d/init.sql
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
|
||||
@@ -79,7 +79,7 @@ SELECT
|
||||
"
|
||||
|
||||
# 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 "Connection string: $RELSPEC_TEST_PG_CONN"
|
||||
|
||||
@@ -21,7 +21,7 @@ CONTAINER_NAME="relspec-test-postgres"
|
||||
POSTGRES_USER="relspec"
|
||||
POSTGRES_PASSWORD="relspec_test_password"
|
||||
POSTGRES_DB="relspec_test"
|
||||
POSTGRES_PORT="5433"
|
||||
POSTGRES_PORT="5439"
|
||||
|
||||
# Check if podman is available
|
||||
if ! command -v podman &> /dev/null; then
|
||||
|
||||
Reference in New Issue
Block a user