Files
artex/evidence/testmain_test.go
T
dela 0335d572de
ci / go (push) Waiting to run
ci / go-db (agent) (push) Waiting to run
ci / go-db (config) (push) Waiting to run
ci / go-db (db) (push) Waiting to run
ci / go-db (evidence) (push) Waiting to run
ci / go-db (llmrec) (push) Waiting to run
ci / go-db (server) (push) Waiting to run
web / web (push) Waiting to run
docs / links (push) Canceled after 0s
detections / detections (push) Canceled after 0s
First Commit
2026-10-09 08:38:16 +08:00

36 lines
827 B
Go

package evidence
import (
"context"
"os"
"testing"
"github.com/Autumn-27/artex/db"
)
// Initialize an explicitly configured fresh database before taking the same
// suite lock as db, agent and server. Hold it on one pinned connection.
func TestMain(m *testing.M) {
if os.Getenv("ARTEX_PG_DSN") == "" {
os.Exit(m.Run())
}
os.Exit(runEvidenceSuite(m))
}
func runEvidenceSuite(m *testing.M) int {
pg, err := db.Open(os.Getenv("ARTEX_PG_DSN"))
if err != nil {
panic(err)
}
defer pg.Close()
conn, err := pg.Conn(context.Background())
if err != nil {
panic(err)
}
defer conn.Close()
if _, err = conn.ExecContext(context.Background(), `SELECT pg_advisory_lock(7337741002)`); err != nil {
panic(err)
}
defer conn.ExecContext(context.Background(), `SELECT pg_advisory_unlock(7337741002)`)
return m.Run()
}