Files
sqlite3/vfs/registry_test.go

65 lines
1.1 KiB
Go
Raw Normal View History

2023-06-01 18:11:37 +01:00
package vfs_test
2023-05-17 14:04:00 +01:00
import (
"testing"
"github.com/ncruces/go-sqlite3"
_ "github.com/ncruces/go-sqlite3/embed"
2023-06-01 18:11:37 +01:00
"github.com/ncruces/go-sqlite3/vfs"
2023-05-17 14:04:00 +01:00
)
type testVFS struct {
*testing.T
}
2023-06-01 18:11:37 +01:00
func (t testVFS) Open(name string, flags vfs.OpenFlag) (vfs.File, vfs.OpenFlag, error) {
2023-05-17 14:04:00 +01:00
t.Log("Open", name, flags)
t.SkipNow()
return nil, flags, nil
}
2023-05-18 16:00:34 +01:00
func (t testVFS) Delete(name string, syncDir bool) error {
t.Log("Delete", name, syncDir)
2023-05-18 01:34:54 +01:00
return nil
2023-05-17 14:04:00 +01:00
}
2023-06-01 18:11:37 +01:00
func (t testVFS) Access(name string, flags vfs.AccessFlag) (bool, error) {
2023-05-18 01:34:54 +01:00
t.Log("Access", name, flags)
return true, nil
2023-05-17 14:04:00 +01:00
}
func (t testVFS) FullPathname(name string) (string, error) {
t.Log("FullPathname", name)
return name, nil
}
func TestRegister(t *testing.T) {
2023-06-01 18:11:37 +01:00
vfs.Register("foo", testVFS{t})
defer vfs.Unregister("foo")
2023-05-17 14:04:00 +01:00
conn, err := sqlite3.Open("file:file.db?vfs=foo")
if err != nil {
t.Fatal(err)
}
defer conn.Close()
2023-05-18 16:00:34 +01:00
t.Error("want skip")
2023-05-17 14:04:00 +01:00
}
2024-07-23 13:28:09 +01:00
func TestRegister_os(t *testing.T) {
os := vfs.Find("os")
if os == nil {
t.Fail()
}
vfs.Register("os", testVFS{t})
if vfs.Find("os") != os {
t.Fail()
}
vfs.Unregister("os")
if vfs.Find("os") != os {
t.Fail()
}
}