github.com/ncruces/go-sqlite3@v0.15.1-0.20240520133447-53eef1510ff0/vfs/adiantum/adiantum_test.go (about) 1 package adiantum_test 2 3 import ( 4 _ "embed" 5 "path/filepath" 6 "strings" 7 "testing" 8 9 "github.com/ncruces/go-sqlite3" 10 "github.com/ncruces/go-sqlite3/driver" 11 _ "github.com/ncruces/go-sqlite3/embed" 12 _ "github.com/ncruces/go-sqlite3/tests/testcfg" 13 "github.com/ncruces/go-sqlite3/util/ioutil" 14 "github.com/ncruces/go-sqlite3/vfs" 15 "github.com/ncruces/go-sqlite3/vfs/adiantum" 16 "github.com/ncruces/go-sqlite3/vfs/readervfs" 17 ) 18 19 //go:embed testdata/test.db 20 var testDB string 21 22 func Test_fileformat(t *testing.T) { 23 readervfs.Create("test.db", ioutil.NewSizeReaderAt(strings.NewReader(testDB))) 24 adiantum.Register("radiantum", vfs.Find("reader"), nil) 25 26 db, err := driver.Open("file:test.db?vfs=radiantum", nil) 27 if err != nil { 28 t.Fatal(err) 29 } 30 defer db.Close() 31 32 _, err = db.Exec(`PRAGMA textkey='correct+horse+battery+staple'`) 33 if err != nil { 34 t.Fatal(err) 35 } 36 37 var version uint32 38 err = db.QueryRow(`PRAGMA user_version`).Scan(&version) 39 if err != nil { 40 t.Fatal(err) 41 } 42 if version != 0xBADDB { 43 t.Error(version) 44 } 45 } 46 47 func Benchmark_nokey(b *testing.B) { 48 tmp := filepath.Join(b.TempDir(), "test.db") 49 sqlite3.Initialize() 50 b.ResetTimer() 51 52 for n := 0; n < b.N; n++ { 53 db, err := sqlite3.Open("file:" + filepath.ToSlash(tmp) + "?nolock=1") 54 if err != nil { 55 b.Fatal(err) 56 } 57 db.Close() 58 } 59 } 60 func Benchmark_hexkey(b *testing.B) { 61 tmp := filepath.Join(b.TempDir(), "test.db") 62 sqlite3.Initialize() 63 b.ResetTimer() 64 65 for n := 0; n < b.N; n++ { 66 db, err := sqlite3.Open("file:" + filepath.ToSlash(tmp) + "?nolock=1" + 67 "&vfs=adiantum&hexkey=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") 68 if err != nil { 69 b.Fatal(err) 70 } 71 db.Close() 72 } 73 } 74 75 func Benchmark_textkey(b *testing.B) { 76 tmp := filepath.Join(b.TempDir(), "test.db") 77 sqlite3.Initialize() 78 b.ResetTimer() 79 80 for n := 0; n < b.N; n++ { 81 db, err := sqlite3.Open("file:" + filepath.ToSlash(tmp) + "?nolock=1" + 82 "&vfs=adiantum&textkey=correct+horse+battery+staple") 83 if err != nil { 84 b.Fatal(err) 85 } 86 db.Close() 87 } 88 }