Fork of ncruces/go-sqlite3 (MIT, retained). Renames module to github.com/hanzoai/sqlite3 (wasm blob stays upstream ncruces/go-sqlite3-wasm) and adds the hanzovfs package: a pure-Go, no-FUSE SQLite VFS that seals pages with ChaCha20-Poly1305 (per-tenant DEK, HIP-0302) for per-tenant SQLite ⇒ hanzoai/vfs ⇒ S3. Deprecates modernc.org/sqlite (no custom-VFS hook) and direct ncruces use. Benchmarked 3.6x faster writes / ~92x faster point-reads than FUSE; encryption ~free. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
102 lines
1.9 KiB
Go
102 lines
1.9 KiB
Go
package tests
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hanzoai/sqlite3"
|
|
"github.com/hanzoai/sqlite3/internal/testcfg"
|
|
)
|
|
|
|
func Test_base64(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
db, err := sqlite3.OpenContext(testcfg.Context(t), ":memory:")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer db.Close()
|
|
|
|
tests := []struct {
|
|
s string
|
|
want string
|
|
}{
|
|
{"x''", ""},
|
|
{"''", ""},
|
|
|
|
{"x'000102030405'", "AAECAwQF"},
|
|
{"x'0001020304'", "AAECAwQ="},
|
|
{"x'00010203'", "AAECAw=="},
|
|
|
|
{"'AAECAwQF'", "\x00\x01\x02\x03\x04\x05"},
|
|
{"'AAECAwQ='", "\x00\x01\x02\x03\x04"},
|
|
{"'AAECAw=='", "\x00\x01\x02\x03"},
|
|
|
|
{"' AAECAwQF '", "\x00\x01\x02\x03\x04\x05"},
|
|
{"' AAECAwQ'", "\x00\x01\x02\x03\x04"},
|
|
{"' AAECAw '", "\x00\x01\x02\x03"},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run("", func(t *testing.T) {
|
|
stmt, _, err := db.Prepare(`SELECT base64(` + tt.s + `)`)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
defer stmt.Close()
|
|
|
|
if !stmt.Step() {
|
|
t.Fatal("expected one row")
|
|
}
|
|
if got := stmt.ColumnText(0); got != tt.want {
|
|
t.Errorf("got %q, want %q", got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func Test_decimal(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
db, err := sqlite3.OpenContext(testcfg.Context(t), ":memory:")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer db.Close()
|
|
|
|
stmt, _, err := db.Prepare(`SELECT decimal_add(decimal('0.1'), decimal('0.2')) = decimal('0.3')`)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
defer stmt.Close()
|
|
|
|
if !stmt.Step() {
|
|
t.Fatal("expected one row")
|
|
}
|
|
if !stmt.ColumnBool(0) {
|
|
t.Error("want true")
|
|
}
|
|
}
|
|
|
|
func Test_uint(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
db, err := sqlite3.OpenContext(testcfg.Context(t), ":memory:")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer db.Close()
|
|
|
|
stmt, _, err := db.Prepare(`SELECT 'z2' < 'z11' COLLATE UINT`)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
defer stmt.Close()
|
|
|
|
if !stmt.Step() {
|
|
t.Fatal("expected one row")
|
|
}
|
|
if !stmt.ColumnBool(0) {
|
|
t.Error("want true")
|
|
}
|
|
}
|