f99010fae1
CI / lint (push) Failing after 1s
CI / frontend (push) Failing after 1s
CI / scripts (push) Failing after 1s
CI / Go Test (ubuntu-latest) (push) Failing after 0s
CI / frontend-node-25 (push) Failing after 1s
CI / docs (push) Failing after 0s
CI / coverage (push) Failing after 0s
CI / e2e (push) Failing after 0s
Docker / build-and-push (push) Failing after 1s
CI / integration (push) Failing after 4m43s
CI / Go Test (windows-latest) (push) Has been cancelled
CI / Desktop Unit Tests (Windows) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux (arm64)) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Windows) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (aarch64)) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (x86_64)) (push) Has been cancelled
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package db
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"database/sql"
|
|
"fmt"
|
|
)
|
|
|
|
// OpenPreparedTestDB opens a private test database file that has already been
|
|
// initialized with the current schema and data version. It is intentionally
|
|
// test-only so production code cannot bypass the normal open/migration path.
|
|
func OpenPreparedTestDB(path string) (*DB, error) {
|
|
writer, err := sql.Open("sqlite3", makeDSN(path, false))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("opening prepared test writer: %w", err)
|
|
}
|
|
writer.SetMaxOpenConns(1)
|
|
if err := configureWAL(writer); err != nil {
|
|
writer.Close()
|
|
return nil, fmt.Errorf("configuring prepared test wal: %w", err)
|
|
}
|
|
|
|
reader, err := sql.Open("sqlite3", makeDSN(path, true))
|
|
if err != nil {
|
|
writer.Close()
|
|
return nil, fmt.Errorf("opening prepared test reader: %w", err)
|
|
}
|
|
reader.SetMaxOpenConns(4)
|
|
|
|
db := &DB{path: path}
|
|
db.writer.Store(writer)
|
|
db.reader.Store(reader)
|
|
|
|
db.cursorSecret = make([]byte, 32)
|
|
if _, err := rand.Read(db.cursorSecret); err != nil {
|
|
writer.Close()
|
|
reader.Close()
|
|
return nil, fmt.Errorf(
|
|
"generating prepared test cursor secret: %w", err,
|
|
)
|
|
}
|
|
|
|
db.startWALCheckpointLoop()
|
|
return db, nil
|
|
}
|