chore(testserver): host networking, ports 8123/8124, smoke read+update, dbtrace pooled=0 verified

This commit is contained in:
2026-09-30 23:01:52 +02:00
parent ff76eb8e1f
commit da0b1f5123
7 changed files with 18 additions and 21 deletions
+2 -1
View File
@@ -95,7 +95,8 @@
- DONE P6: funcspec. `OnTxBegin`, `HookContext.SetTx`, `Handler.runInTx` for `SqlQuery` and `SqlQueryList`. `BeforeResponse` now runs in a second short tx (`Tx` is no longer the pool). `BeforeOp` is unchanged (still per statement). A begin/`OnTxBegin`/commit failure answers 500 `transaction_error` / "Transaction failed" (before, it returned with no response); body failures still answer via `sendError`. Tests: `pkg/funcspec/tx_test.go`.
- DONE (AfterRead, decided by user): restheadspec `AfterRead` now runs in a second short tx. Test: `pkg/restheadspec/read_tx_test.go`.
- DONE P7: `pkg/security/txsettings.go`: `SecurityList.SetTxSettings(fn)`, `StampTxSettings`, `ApplyTxSettings` (configurable map, decided by user; `set_config(name, value, true)`, value hex-encoded, name validated, Postgres only, fail closed). Every spec's `RegisterSecurityHooks` registers it on `OnTxBegin`. Tests: `pkg/security/txsettings_test.go`, `pkg/resolvespec/tx_settings_test.go`. Docs: `pkg/common/TRANSACTIONS.md`.
- NEXT: extra tests (create/update for other specs, `dbtrace` `pooled == 0` on real Postgres).
- DONE real-Postgres check (resolvespec, testserver via compose): create `tx=1 pooled=0`, read `tx=1 pooled=0`, update `tx=2 pooled=0` (was `pooled=1`), single delete `tx=1 pooled=0`, batch create/delete `tx=1 pooled=0`. Compose now uses host networking (bridge fails here): testserver on 8123, Postgres on 8124 (was 8080/5434); integration test DSNs updated. Smoke script covers read and update. websocketspec/mqttspec/resolvemcp/restheadspec/funcspec not measured on real Postgres.
- NEXT: extra per-spec create/update tests (optional).
## Tests
- Existing: per-spec `handler_test.go`, `hooks_test.go`, `integration_test.go`; models in `pkg/testmodels/business.go`; `dbtrace` unit tests.
+7 -13
View File
@@ -6,17 +6,17 @@ services:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- "5434:5432"
# Host networking (bridge networks are unavailable in some environments):
# postgres listens directly on host port 8124.
network_mode: host
command: ["postgres", "-p", "8124"]
volumes:
- postgres-test-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
test: ["CMD-SHELL", "pg_isready -U postgres -p 8124"]
interval: 5s
timeout: 5s
retries: 5
networks:
- resolvespec-test
testserver:
build:
@@ -27,18 +27,12 @@ services:
RESOLVESPEC_DB_TRACE_ENABLED: "true"
RESOLVESPEC_DB_TRACE_MIN_CALLS: "1"
RESOLVESPEC_DB_TRACE_POOL_LOG: "true"
ports:
- "8080:8080"
# Serves on host port 8123 (docker/testserver.config.yaml).
network_mode: host
depends_on:
postgres-test:
condition: service_healthy
networks:
- resolvespec-test
volumes:
postgres-test-data:
driver: local
networks:
resolvespec-test:
driver: bridge
+1 -1
View File
@@ -9,5 +9,5 @@ FROM alpine:3.20
RUN apk add --no-cache ca-certificates
COPY --from=build /out/testserver /usr/local/bin/testserver
COPY docker/testserver.config.yaml /etc/resolvespec/config.yaml
EXPOSE 8080
EXPOSE 8123
ENTRYPOINT ["testserver"]
+3 -3
View File
@@ -12,7 +12,7 @@ servers:
main:
name: "main"
host: "0.0.0.0"
port: 8080
port: 8123
description: "Main server instance"
gzip: true
tags:
@@ -79,8 +79,8 @@ dbmanager:
default:
name: "default"
type: "postgres"
host: "postgres-test"
port: 5432
host: "localhost"
port: 8124
user: "postgres"
password: "postgres"
database: "postgres"
+1 -1
View File
@@ -67,7 +67,7 @@ func setupTestDB(t *testing.T) *gorm.DB {
// Get connection string from environment or use default
dsn := os.Getenv("TEST_DATABASE_URL")
if dsn == "" {
dsn = "host=localhost user=postgres password=postgres dbname=resolvespec_test port=5434 sslmode=disable"
dsn = "host=localhost user=postgres password=postgres dbname=resolvespec_test port=8124 sslmode=disable"
}
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{
+1 -1
View File
@@ -67,7 +67,7 @@ func setupTestDB(t *testing.T) *gorm.DB {
// Get connection string from environment or use default
dsn := os.Getenv("TEST_DATABASE_URL")
if dsn == "" {
dsn = "host=localhost user=postgres password=postgres dbname=restheadspec_test port=5434 sslmode=disable"
dsn = "host=localhost user=postgres password=postgres dbname=restheadspec_test port=8124 sslmode=disable"
}
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{
+3 -1
View File
@@ -3,7 +3,7 @@
# Usage: scripts/testserver-smoke.sh [base_url] (COMPOSE overrides the compose command)
set -euo pipefail
BASE="${1:-http://localhost:8080}"
BASE="${1:-http://localhost:8123}"
if [ -z "${COMPOSE:-}" ]; then
if command -v podman >/dev/null 2>&1; then COMPOSE="podman compose"; else COMPOSE="docker compose"; fi
fi
@@ -24,6 +24,8 @@ ids() { grep -o '"id":[0-9]*' "$BODY" | cut -d: -f2; }
expect create 200 "$(call "{\"operation\":\"create\",\"data\":{\"name\":\"Smoke\",\"code\":\"S$TS\"}}")"
ID="$(ids | head -1)"
expect read 200 "$(call '{"operation":"read"}' "/$ID")"
expect update 200 "$(call '{"operation":"update","data":{"name":"Smoke2"}}' "/$ID")"
expect delete 200 "$(call '{"operation":"delete"}' "/$ID")"
expect delete-again 404 "$(call '{"operation":"delete"}' "/$ID")"