Fix file format.

This commit is contained in:
Nuno Cruces
2024-05-07 16:34:51 +01:00
parent 34882e7c8d
commit 4d23fc3cee
4 changed files with 46 additions and 12 deletions

View File

@@ -16,10 +16,10 @@ import (
)
//go:embed testdata/wal.db
var waldb []byte
var walDB []byte
//go:embed testdata/utf16be.db
var utf16db []byte
var utf16DB []byte
func TestDB_memory(t *testing.T) {
t.Parallel()
@@ -42,7 +42,7 @@ func TestDB_wal(t *testing.T) {
t.Parallel()
tmp := filepath.Join(t.TempDir(), "test.db")
err := os.WriteFile(tmp, waldb, 0666)
err := os.WriteFile(tmp, walDB, 0666)
if err != nil {
t.Fatal(err)
}
@@ -56,7 +56,7 @@ func TestDB_utf16(t *testing.T) {
t.Parallel()
tmp := filepath.Join(t.TempDir(), "test.db")
err := os.WriteFile(tmp, utf16db, 0666)
err := os.WriteFile(tmp, utf16DB, 0666)
if err != nil {
t.Fatal(err)
}

View File

@@ -26,7 +26,7 @@ func TestWAL_enter_exit(t *testing.T) {
defer db.Close()
if !vfs.SupportsSharedMemory {
err = db.Exec(`PRAGMA locking_mode=EXCLUSIVE`)
err = db.Exec(`PRAGMA locking_mode=exclusive`)
if err != nil {
t.Fatal(err)
}
@@ -34,11 +34,11 @@ func TestWAL_enter_exit(t *testing.T) {
err = db.Exec(`
CREATE TABLE test (col);
PRAGMA journal_mode=WAL;
PRAGMA journal_mode=wal;
SELECT * FROM test;
PRAGMA journal_mode=DELETE;
PRAGMA journal_mode=delete;
SELECT * FROM test;
PRAGMA journal_mode=WAL;
PRAGMA journal_mode=wal;
SELECT * FROM test;
`)
if err != nil {
@@ -53,7 +53,7 @@ func TestWAL_readonly(t *testing.T) {
t.Parallel()
tmp := filepath.Join(t.TempDir(), "test.db")
err := os.WriteFile(tmp, waldb, 0666)
err := os.WriteFile(tmp, walDB, 0666)
if err != nil {
t.Fatal(err)
}
@@ -101,8 +101,8 @@ func TestConn_WalCheckpoint(t *testing.T) {
})
err = db.Exec(`
PRAGMA locking_mode=EXCLUSIVE;
PRAGMA journal_mode=WAL;
PRAGMA locking_mode=exlusive;
PRAGMA journal_mode=wal;
CREATE TABLE test (col);
`)
if err != nil {

View File

@@ -1,14 +1,48 @@
package adiantum_test
import (
_ "embed"
"path/filepath"
"strings"
"testing"
"github.com/ncruces/go-sqlite3"
"github.com/ncruces/go-sqlite3/driver"
_ "github.com/ncruces/go-sqlite3/embed"
_ "github.com/ncruces/go-sqlite3/vfs/adiantum"
"github.com/ncruces/go-sqlite3/util/ioutil"
"github.com/ncruces/go-sqlite3/vfs"
"github.com/ncruces/go-sqlite3/vfs/adiantum"
"github.com/ncruces/go-sqlite3/vfs/readervfs"
)
//go:embed testdata/test.db
var testDB string
func Test_fileformat(t *testing.T) {
readervfs.Create("test.db", ioutil.NewSizeReaderAt(strings.NewReader(testDB)))
adiantum.Register("adiantum", vfs.Find("reader"), nil)
db, err := driver.Open("file:test.db?vfs=adiantum", nil)
if err != nil {
t.Fatal(err)
}
defer db.Close()
_, err = db.Exec(`PRAGMA textkey='correct+horse+battery+staple'`)
if err != nil {
t.Fatal(err)
}
var version uint32
err = db.QueryRow(`PRAGMA user_version`).Scan(&version)
if err != nil {
t.Fatal(err)
}
if version != 0xBADDB {
t.Error(version)
}
}
func Benchmark_nokey(b *testing.B) {
tmp := filepath.Join(b.TempDir(), "test.db")
sqlite3.Initialize()

BIN
vfs/adiantum/testdata/test.db vendored Normal file

Binary file not shown.