mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-15 04:30:55 +08:00
traffic_evidence_snapshots.req_head and resp_head join the secret column registry (AAD per column, enc:v1:). Heads are sealed at insert and opened on every read; the startup key check, the no-key refusal and the idempotent backfill cover them. Archives keep the heads sealed; the import opens them to check the snapshot ID and the insert seals them once.
44 lines
1.2 KiB
Go
44 lines
1.2 KiB
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) {
|
|
// Own database per package (#80): stop contending on the shared tables of
|
|
// a single test database during parallel ./... runs.
|
|
db.SuffixTestDatabase("evidence")
|
|
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)`)
|
|
// Snapshot inserts seal the heads: load a fixed test key (env, no key file).
|
|
os.Setenv("ARTEX_SECRET_KEY", "MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY=")
|
|
if err = pg.InitSecrets(""); err != nil {
|
|
panic(err)
|
|
}
|
|
return m.Run()
|
|
}
|