Really?
This commit is contained in:
53
.github/workflows/integration-tests.yml
vendored
53
.github/workflows/integration-tests.yml
vendored
@@ -31,11 +31,28 @@ jobs:
|
|||||||
- name: Download dependencies
|
- name: Download dependencies
|
||||||
run: go mod download
|
run: go mod download
|
||||||
|
|
||||||
|
- name: Create Docker network and connect runner
|
||||||
|
run: |
|
||||||
|
# Create network
|
||||||
|
docker network create relspec-test-network || true
|
||||||
|
|
||||||
|
# Get current container ID (the runner)
|
||||||
|
RUNNER_CONTAINER_ID=$(cat /proc/self/cgroup | grep 'docker\|kubepods' | head -1 | sed 's/^.*\///' | cut -d':' -f3 | sed 's/^.*\///')
|
||||||
|
if [ -z "$RUNNER_CONTAINER_ID" ]; then
|
||||||
|
# Alternative method: use hostname which is often the container ID
|
||||||
|
RUNNER_CONTAINER_ID=$(hostname)
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Runner container ID: $RUNNER_CONTAINER_ID"
|
||||||
|
|
||||||
|
# Connect runner to the network so tests can access PostgreSQL by hostname
|
||||||
|
docker network connect relspec-test-network "$RUNNER_CONTAINER_ID" 2>/dev/null || echo "Already connected or unable to connect"
|
||||||
|
|
||||||
- name: Start PostgreSQL container
|
- name: Start PostgreSQL container
|
||||||
run: |
|
run: |
|
||||||
docker run -d \
|
docker run -d \
|
||||||
--name relspec-test-postgres \
|
--name relspec-test-postgres \
|
||||||
-p 5439:5432 \
|
--network relspec-test-network \
|
||||||
-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 \
|
||||||
@@ -58,19 +75,10 @@ jobs:
|
|||||||
- name: Get PostgreSQL connection details
|
- name: Get PostgreSQL connection details
|
||||||
id: pg_connection
|
id: pg_connection
|
||||||
run: |
|
run: |
|
||||||
# Get container IP address from Docker bridge network
|
# Use container name for DNS resolution on the Docker network
|
||||||
# This is needed because the runner itself is in a Docker container
|
# This works because both containers are on the same custom network
|
||||||
CONTAINER_IP=$(docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' relspec-test-postgres)
|
echo "Using container hostname: relspec-test-postgres:5432"
|
||||||
|
echo "pg_host=relspec-test-postgres" >> $GITHUB_OUTPUT
|
||||||
if [ -z "$CONTAINER_IP" ]; then
|
|
||||||
echo "ERROR: Could not get container IP address"
|
|
||||||
docker inspect relspec-test-postgres
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Container IP: $CONTAINER_IP"
|
|
||||||
echo "Using container IP: $CONTAINER_IP:5432"
|
|
||||||
echo "pg_host=$CONTAINER_IP" >> $GITHUB_OUTPUT
|
|
||||||
echo "pg_port=5432" >> $GITHUB_OUTPUT
|
echo "pg_port=5432" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
@@ -93,11 +101,11 @@ jobs:
|
|||||||
"
|
"
|
||||||
|
|
||||||
- name: Test Go connection to PostgreSQL
|
- name: Test Go connection to PostgreSQL
|
||||||
env:
|
|
||||||
RELSPEC_TEST_PG_CONN: postgres://relspec:relspec_test_password@${{ steps.pg_connection.outputs.pg_host }}:${{ steps.pg_connection.outputs.pg_port }}/relspec_test
|
|
||||||
run: |
|
run: |
|
||||||
echo "Testing connection using Go (same as integration tests will use)..."
|
echo "Testing connection using Go (same as integration tests will use)..."
|
||||||
echo "Connection string: postgres://relspec:***@${{ steps.pg_connection.outputs.pg_host }}:${{ steps.pg_connection.outputs.pg_port }}/relspec_test"
|
echo "Connection string: postgres://relspec:***@${{ steps.pg_connection.outputs.pg_host }}:${{ steps.pg_connection.outputs.pg_port }}/relspec_test"
|
||||||
|
|
||||||
|
# Create test program
|
||||||
mkdir -p /tmp/testconn
|
mkdir -p /tmp/testconn
|
||||||
cat > /tmp/testconn/test_conn.go << 'EOF'
|
cat > /tmp/testconn/test_conn.go << 'EOF'
|
||||||
package main
|
package main
|
||||||
@@ -123,7 +131,17 @@ jobs:
|
|||||||
fmt.Printf("SUCCESS! Connected to: %s\n", version)
|
fmt.Printf("SUCCESS! Connected to: %s\n", version)
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
cd /tmp/testconn && go mod init testconn && go mod tidy && go run test_conn.go
|
|
||||||
|
# Build the test program
|
||||||
|
cd /tmp/testconn && go mod init testconn && go mod tidy && go build -o test_conn
|
||||||
|
|
||||||
|
# Run in a container on the same network
|
||||||
|
docker run --rm \
|
||||||
|
--network relspec-test-network \
|
||||||
|
-e RELSPEC_TEST_PG_CONN="postgres://relspec:relspec_test_password@${{ steps.pg_connection.outputs.pg_host }}:${{ steps.pg_connection.outputs.pg_port }}/relspec_test" \
|
||||||
|
-v /tmp/testconn:/app \
|
||||||
|
golang:1.25-alpine \
|
||||||
|
/app/test_conn
|
||||||
|
|
||||||
- name: Run integration tests
|
- name: Run integration tests
|
||||||
env:
|
env:
|
||||||
@@ -135,3 +153,4 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
docker stop relspec-test-postgres || true
|
docker stop relspec-test-postgres || true
|
||||||
docker rm relspec-test-postgres || true
|
docker rm relspec-test-postgres || true
|
||||||
|
docker network rm relspec-test-network || true
|
||||||
|
|||||||
Reference in New Issue
Block a user