mirror of
https://github.com/hanzoai/vfs.git
synced 2026-10-30 18:18:21 +00:00
The durability profile was written by hand in modernc's `_pragma=NAME(VALUE)` form, which the cgo backend does not recognise and drops silently — so a cgo build of the replica store ran with journal_mode `delete`, foreign keys off and the default busy timeout while the DSN asked for WAL, ON and 10000. Four call sites, including the handle Restore reopens. sqlite.PragmaDSN emits the form the linked backend reads, so there is one spelling to get right and the driver owns it. The test opens a real file and asks the database what it got: the string is what differs between backends, so a string assertion would pass on the build that ignores it — which is why the hand-written form looked correct.
34 lines
975 B
Go
34 lines
975 B
Go
package replica
|
|
|
|
import (
|
|
"database/sql"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// TestDSNAppliesTheDurabilityProfile opens a real file and asks the database
|
|
// what it got. The DSN string is exactly what differs between the two backends —
|
|
// each ignores the other's spelling — so asserting on the string would pass on
|
|
// the build that ignores it.
|
|
func TestDSNAppliesTheDurabilityProfile(t *testing.T) {
|
|
db, err := sql.Open("sqlite", dsn(filepath.Join(t.TempDir(), "t.db")))
|
|
if err != nil {
|
|
t.Fatalf("open: %v", err)
|
|
}
|
|
defer func() { _ = db.Close() }()
|
|
|
|
for _, c := range []struct{ pragma, want string }{
|
|
{"journal_mode", "wal"},
|
|
{"foreign_keys", "1"},
|
|
{"busy_timeout", "10000"},
|
|
} {
|
|
var got string
|
|
if err := db.QueryRow("PRAGMA " + c.pragma).Scan(&got); err != nil {
|
|
t.Fatalf("PRAGMA %s: %v", c.pragma, err)
|
|
}
|
|
if got != c.want {
|
|
t.Errorf("%s = %q, want %q — the DSN asked for it and the backend did not take it", c.pragma, got, c.want)
|
|
}
|
|
}
|
|
}
|