diff --git a/.gitea/workflows/db-tests.yml b/.gitea/workflows/db-tests.yml new file mode 100644 index 00000000..55651a53 --- /dev/null +++ b/.gitea/workflows/db-tests.yml @@ -0,0 +1,28 @@ +name: DB-Integrationstests + +on: + pull_request: + paths: + - "common/**" + - "dms/**" + - "mail/**" + - "archive/**" + - "ai/**" + - "connect/**" + - "workflow/**" + - "internal/**" + +jobs: + db-tests: + runs-on: nexarch-test + env: + TEST_ADMIN_DSN: ${{ secrets.TEST_ADMIN_DSN }} + REQUIRE_DB: "1" + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: "1.25" + - name: Tests (common) + working-directory: common + run: go test ./testdb/... ./migrate/... -count=1 -p 1 diff --git a/common/testdb/testdb.go b/common/testdb/testdb.go index c5db1b1a..206a6fbe 100644 --- a/common/testdb/testdb.go +++ b/common/testdb/testdb.go @@ -7,6 +7,7 @@ package testdb import ( "context" "fmt" + "os" "sync/atomic" "testing" "time" @@ -16,6 +17,21 @@ import ( var seq atomic.Int64 +// AdminDSN liefert TEST_ADMIN_DSN. Fehlt er, wird uebersprungen; mit +// REQUIRE_DB=1 (CI) zaehlt das Fehlen als Fehler. +func AdminDSN(t testing.TB) string { + t.Helper() + dsn := os.Getenv("TEST_ADMIN_DSN") + if dsn != "" { + return dsn + } + if os.Getenv("REQUIRE_DB") == "1" { + t.Fatal("testdb: TEST_ADMIN_DSN nicht gesetzt, aber REQUIRE_DB=1") + } + t.Skip("testdb: TEST_ADMIN_DSN nicht gesetzt, Integrationstest uebersprungen") + return "" +} + // Pool legt ein Schema an und liefert einen darauf ausgerichteten Pool; // beides wird per t.Cleanup wieder entfernt. func Pool(t testing.TB, dsn string) *pgxpool.Pool { diff --git a/common/testdb/testdb_test.go b/common/testdb/testdb_test.go new file mode 100644 index 00000000..9ef1b4c0 --- /dev/null +++ b/common/testdb/testdb_test.go @@ -0,0 +1,11 @@ +package testdb + +import "testing" + +func TestAdminDSNGesetzt(t *testing.T) { + t.Setenv("TEST_ADMIN_DSN", "postgres://x") + t.Setenv("REQUIRE_DB", "1") + if got := AdminDSN(t); got != "postgres://x" { + t.Fatalf("dsn = %q", got) + } +}