From 567b1d437c278b147c0540a659e912ba276d5a11 Mon Sep 17 00:00:00 2001 From: Hein Date: Fri, 18 Sep 2026 20:38:28 +0200 Subject: [PATCH] fix(tests): update database host from localhost to 127.0.0.1 * Adjust connection strings in integration tests for consistency * Ensure compatibility with CI environments that use IPv4 --- README.md | 2 +- broker.test.yaml | 2 +- tests/integration/connection_test.go | 2 +- tests/integration/rls_test.go | 2 +- tests/integration/stage5_test.go | 4 ++-- tests/integration/workflow_test.go | 6 +++--- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 334eb5b..c8f2a28 100644 --- a/README.md +++ b/README.md @@ -389,7 +389,7 @@ go test -v ./tests/integration/... # integration tests (needs local Postgres docker-compose -f docker-compose.test.yml up --build --abort-on-container-exit --exit-code-from tests ``` -Integration tests expect Postgres reachable at `localhost:5433` (see `tests/integration/`), including `rls_test.go` (multi-tenant isolation) and `stage5_test.go`. +Integration tests expect Postgres reachable at `127.0.0.1:5433` (see `tests/integration/`), including `rls_test.go` (multi-tenant isolation) and `stage5_test.go`. `127.0.0.1` is used instead of `localhost` because some CI Docker hosts publish container ports on IPv4 only, and `localhost` can resolve to `::1` first and fail. ### Project Structure diff --git a/broker.test.yaml b/broker.test.yaml index e7cfe82..cc2c523 100644 --- a/broker.test.yaml +++ b/broker.test.yaml @@ -1,6 +1,6 @@ databases: - name: test - host: localhost + host: 127.0.0.1 port: 5433 database: broker_test user: user diff --git a/tests/integration/connection_test.go b/tests/integration/connection_test.go index 3c93b54..f6330b3 100644 --- a/tests/integration/connection_test.go +++ b/tests/integration/connection_test.go @@ -10,7 +10,7 @@ import ( ) func TestConnection(t *testing.T) { - connStr := "user=user password=password dbname=broker_test port=5433 sslmode=disable" + connStr := "user=user password=password dbname=broker_test host=127.0.0.1 port=5433 sslmode=disable" var db *sql.DB var err error diff --git a/tests/integration/rls_test.go b/tests/integration/rls_test.go index 2c851da..15c97da 100644 --- a/tests/integration/rls_test.go +++ b/tests/integration/rls_test.go @@ -47,7 +47,7 @@ func TestRLSTenantIsolation(t *testing.T) { } runtimeDB, err := sql.Open("postgres", - "user=test_broker_runtime password=test-pass dbname=broker_test host=localhost port=5433 sslmode=disable options='-c search_path=broker,public'") + "user=test_broker_runtime password=test-pass dbname=broker_test host=127.0.0.1 port=5433 sslmode=disable options='-c search_path=broker,public'") require.NoError(t, err) defer runtimeDB.Close() require.NoError(t, runtimeDB.Ping()) diff --git a/tests/integration/stage5_test.go b/tests/integration/stage5_test.go index 5ffe3ca..39710a0 100644 --- a/tests/integration/stage5_test.go +++ b/tests/integration/stage5_test.go @@ -14,11 +14,11 @@ import ( "git.warky.dev/wdevs/pgsql-broker/pkg/broker/install" ) -const stage5ConnStr = "user=user password=password dbname=broker_test host=localhost port=5433 sslmode=disable" +const stage5ConnStr = "user=user password=password dbname=broker_test host=127.0.0.1 port=5433 sslmode=disable" func newStage5Adapter(logger adapter.Logger) *adapter.PostgresAdapter { return adapter.NewPostgresAdapter(adapter.PostgresConfig{ - Host: "localhost", Port: 5433, Database: "broker_test", + Host: "127.0.0.1", Port: 5433, Database: "broker_test", User: "user", Password: "password", SSLMode: "disable", MaxOpenConns: 10, MaxIdleConns: 2, ConnMaxLifetime: 5 * time.Minute, ConnMaxIdleTime: 10 * time.Minute, diff --git a/tests/integration/workflow_test.go b/tests/integration/workflow_test.go index 7c061c2..6e24d43 100644 --- a/tests/integration/workflow_test.go +++ b/tests/integration/workflow_test.go @@ -27,7 +27,7 @@ func TestBrokerWorkflow(t *testing.T) { ctx := context.Background() // Database connection string - connStr := "user=user password=password dbname=broker_test host=localhost port=5433 sslmode=disable" + connStr := "user=user password=password dbname=broker_test host=127.0.0.1 port=5433 sslmode=disable" // Connect to database with retry logic db, err := connectWithRetry(connStr, 10, 2*time.Second) @@ -43,7 +43,7 @@ func TestBrokerWorkflow(t *testing.T) { // Create database adapter postgresConfig := adapter.PostgresConfig{ - Host: "localhost", + Host: "127.0.0.1", Port: 5433, Database: "broker_test", User: "user", @@ -78,7 +78,7 @@ func TestBrokerWorkflow(t *testing.T) { Databases: []config.DatabaseConfig{ { Name: "test_db", - Host: "localhost", + Host: "127.0.0.1", Port: 5433, Database: "broker_test", User: "user",