aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/golite.go288
1 files changed, 27 insertions, 261 deletions
diff --git a/tests/golite.go b/tests/golite.go
index 1dc01c4..3f09878 100644
--- a/tests/golite.go
+++ b/tests/golite.go
@@ -474,11 +474,6 @@ func TestExtendedErrorCodes_ForeignKey(t *testing.T) {
}
defer db.Close()
- _, err = db.Exec("PRAGMA foreign_keys=ON;")
- if err != nil {
- t.Errorf("PRAGMA foreign_keys=ON: %v", err)
- }
-
_, err = db.Exec(`CREATE TABLE Foo (
id INTEGER PRIMARY KEY AUTOINCREMENT,
value INTEGER NOT NULL,
@@ -519,11 +514,6 @@ func TestExtendedErrorCodes_NotNull(t *testing.T) {
}
defer db.Close()
- _, err = db.Exec("PRAGMA foreign_keys=ON;")
- if err != nil {
- t.Errorf("PRAGMA foreign_keys=ON: %v", err)
- }
-
_, err = db.Exec(`CREATE TABLE Foo (
id INTEGER PRIMARY KEY AUTOINCREMENT,
value INTEGER NOT NULL,
@@ -574,11 +564,6 @@ func TestExtendedErrorCodes_Unique(t *testing.T) {
}
defer db.Close()
- _, err = db.Exec("PRAGMA foreign_keys=ON;")
- if err != nil {
- t.Errorf("PRAGMA foreign_keys=ON: %v", err)
- }
-
_, err = db.Exec(`CREATE TABLE Foo (
id INTEGER PRIMARY KEY AUTOINCREMENT,
value INTEGER NOT NULL,
@@ -1022,17 +1007,17 @@ func doTestOpenContext(t *testing.T, url string) (string, error) {
}
}()
- ctx, cancel := context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
err = db.PingContext(ctx)
cancel()
if err != nil {
return "ping error:", err
}
- ctx, cancel = context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
_, err = db.ExecContext(ctx, "drop table foo")
cancel()
- ctx, cancel = context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
_, err = db.ExecContext(ctx, "create table foo (id integer)")
cancel()
if err != nil {
@@ -1042,70 +1027,35 @@ func doTestOpenContext(t *testing.T, url string) (string, error) {
return "", nil
}
-func TestOpenContext(t *testing.T) {
- cases := map[string]bool{
- "file:openctx1?mode=memory&cache=shared": true,
- "file:openctx2?mode=memory&cache=shared&_txlock=immediate": true,
- "file:openctx3?mode=memory&cache=shared&_txlock=deferred": true,
- "file:openctx4?mode=memory&cache=shared&_txlock=exclusive": true,
- "file:openctx5?mode=memory&cache=shared&_txlock=bogus": false,
- }
- for option, expectedPass := range cases {
- result, err := doTestOpenContext(t, option)
- if result == "" {
- if !expectedPass {
- errmsg := fmt.Sprintf("_txlock error not caught at dbOpen with option: %s", option)
- t.Fatal(errmsg)
- }
- } else if expectedPass {
- if err == nil {
- t.Fatal(result)
- } else {
- t.Fatal(result, err)
- }
- }
- }
-}
-
func TestFileCopyTruncate(t *testing.T) {
var err error
tempFilename := TempFilename(t)
-
- defer func() {
- err = os.Remove(tempFilename)
- if err != nil {
- t.Error("temp file remove error:", err)
- }
- }()
+ defer os.Remove(tempFilename)
db, err := sql.Open("golite", tempFilename)
if err != nil {
t.Fatal("open error:", err)
}
+ defer db.Close()
- defer func() {
- err = db.Close()
- if err != nil {
- t.Error("db close error:", err)
- }
- }()
-
+ if true {
_, err = db.Exec("PRAGMA journal_mode = delete;")
if err != nil {
t.Fatal("journal_mode delete:", err)
}
+ }
- ctx, cancel := context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
err = db.PingContext(ctx)
cancel()
if err != nil {
t.Fatal("ping error:", err)
}
- ctx, cancel = context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
_, err = db.ExecContext(ctx, "drop table foo")
cancel()
- ctx, cancel = context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
_, err = db.ExecContext(ctx, "create table foo (id integer)")
cancel()
if err != nil {
@@ -1120,17 +1070,12 @@ func TestFileCopyTruncate(t *testing.T) {
}
var f *os.File
- f, err = os.Create(tempFilename + "-db-copy")
+ copyFilename := tempFilename + "-db-copy"
+ f, err = os.Create(copyFilename)
if err != nil {
t.Fatal("create file error:", err)
}
-
- defer func() {
- err = os.Remove(tempFilename + "-db-copy")
- if err != nil {
- t.Error("temp file moved remove error:", err)
- }
- }()
+ defer os.Remove(copyFilename)
_, err = f.Write(data)
if err != nil {
@@ -1153,21 +1098,21 @@ func TestFileCopyTruncate(t *testing.T) {
}
// test db after file truncate
- ctx, cancel = context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
err = db.PingContext(ctx)
cancel()
if err != nil {
t.Fatal("ping error:", err)
}
- ctx, cancel = context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel = context.WithTimeout(context.Background(), 5*time.Millisecond)
_, err = db.ExecContext(ctx, "drop table foo")
cancel()
if err == nil {
t.Fatal("drop table no error")
}
- ctx, cancel = context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
_, err = db.ExecContext(ctx, "create table foo (id integer)")
cancel()
if err != nil {
@@ -1180,33 +1125,27 @@ func TestFileCopyTruncate(t *testing.T) {
}
// test copied file
- db, err = sql.Open("golite", tempFilename+"-db-copy")
+ db, err = sql.Open("golite", copyFilename)
if err != nil {
t.Fatal("open error:", err)
}
+ defer db.Close()
- defer func() {
- err = db.Close()
- if err != nil {
- t.Error("db close error:", err)
- }
- }()
-
- ctx, cancel = context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
err = db.PingContext(ctx)
cancel()
if err != nil {
t.Fatal("ping error:", err)
}
- ctx, cancel = context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
_, err = db.ExecContext(ctx, "drop table foo")
cancel()
if err != nil {
t.Fatal("drop table error:", err)
}
- ctx, cancel = context.WithTimeout(context.Background(), 55*time.Second)
+ ctx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
_, err = db.ExecContext(ctx, "create table foo (id integer)")
cancel()
if err != nil {
@@ -1392,113 +1331,6 @@ type preUpdateHookDataForTest struct {
newRow []any
}
-/*
-func TestPreUpdateHook(t *testing.T) {
- var events []preUpdateHookDataForTest
-
- sql.Register("sqlite3_PreUpdateHook", &SQLiteDriver{
- ConnectHook: func(conn *SQLiteConn) error {
- conn.RegisterPreUpdateHook(func(data SQLitePreUpdateData) {
- eval := -1
- oldRow := []any{eval}
- if data.Op != SQLITE_INSERT {
- err := data.Old(oldRow...)
- if err != nil {
- t.Fatalf("Unexpected error calling SQLitePreUpdateData.Old: %v", err)
- }
- }
-
- eval2 := -1
- newRow := []any{eval2}
- if data.Op != SQLITE_DELETE {
- err := data.New(newRow...)
- if err != nil {
- t.Fatalf("Unexpected error calling SQLitePreUpdateData.New: %v", err)
- }
- }
-
- // tests dest bound checks in loop
- var tooSmallRow []any
- if data.Op != SQLITE_INSERT {
- err := data.Old(tooSmallRow...)
- if err != nil {
- t.Fatalf("Unexpected error calling SQLitePreUpdateData.Old: %v", err)
- }
- if len(tooSmallRow) != 0 {
- t.Errorf("Expected tooSmallRow to be empty, got: %v", tooSmallRow)
- }
- }
-
- events = append(events, preUpdateHookDataForTest{
- databaseName: data.DatabaseName,
- tableName: data.TableName,
- count: data.Count(),
- op: data.Op,
- oldRow: oldRow,
- newRow: newRow,
- })
- })
- return nil
- },
- })
-
- db, err := sql.Open("sqlite3_PreUpdateHook", ":memory:")
- if err != nil {
- t.Fatal("Failed to open database:", err)
- }
- defer db.Close()
-
- statements := []string{
- "create table foo (id integer primary key)",
- "insert into foo values (9)",
- "update foo set id = 99 where id = 9",
- "delete from foo where id = 99",
- }
- for _, statement := range statements {
- _, err = db.Exec(statement)
- if err != nil {
- t.Fatalf("Unable to prepare test data [%v]: %v", statement, err)
- }
- }
-
- if len(events) != 3 {
- t.Errorf("Events should be 3 entries, got: %d", len(events))
- }
-
- if events[0].op != SQLITE_INSERT {
- t.Errorf("Op isn't as expected: %v", events[0].op)
- }
-
- if events[1].op != SQLITE_UPDATE {
- t.Errorf("Op isn't as expected: %v", events[1].op)
- }
-
- if events[1].count != 1 {
- t.Errorf("Expected event row 1 to have 1 column, had: %v", events[1].count)
- }
-
- newRow_0_0 := events[0].newRow[0].(int64)
- if newRow_0_0 != 9 {
- t.Errorf("Expected event row 0 new column 0 to be == 9, got: %v", newRow_0_0)
- }
-
- oldRow_1_0 := events[1].oldRow[0].(int64)
- if oldRow_1_0 != 9 {
- t.Errorf("Expected event row 1 old column 0 to be == 9, got: %v", oldRow_1_0)
- }
-
- newRow_1_0 := events[1].newRow[0].(int64)
- if newRow_1_0 != 99 {
- t.Errorf("Expected event row 1 new column 0 to be == 99, got: %v", newRow_1_0)
- }
-
- oldRow_2_0 := events[2].oldRow[0].(int64)
- if oldRow_2_0 != 99 {
- t.Errorf("Expected event row 1 new column 0 to be == 99, got: %v", oldRow_2_0)
- }
-}
-*/
-
func TestSerializeDeserialize(t *testing.T) {
// Connect to the source database.
srcDb, err := sql.Open(driverName, "file:src?mode=memory&cache=shared")
@@ -1527,7 +1359,7 @@ func TestSerializeDeserialize(t *testing.T) {
if err != nil {
t.Fatal("Failed to create table in source database:", err)
}
- _, err = srcDb.Exec(`INSERT INTO foo(name) VALUES("alice")`)
+ _, err = srcDb.Exec(`INSERT INTO foo(name) VALUES('alice')`)
if err != nil {
t.Fatal("Failed to insert data into source database", err)
}
@@ -1587,7 +1419,7 @@ func TestSerializeDeserialize(t *testing.T) {
func TestUnlockNotify(t *testing.T) {
tempFilename := TempFilename(t)
defer os.Remove(tempFilename)
- dsn := fmt.Sprintf("file:%s?cache=shared&mode=memory&_busy_timeout=%d", tempFilename, 500)
+ dsn := fmt.Sprintf("file:%s?cache=shared&mode=memory", tempFilename)
db, err := sql.Open("golite", dsn)
if err != nil {
t.Fatal("Failed to open database:", err)
@@ -1647,7 +1479,7 @@ func TestUnlockNotify(t *testing.T) {
func TestUnlockNotifyMany(t *testing.T) {
tempFilename := TempFilename(t)
defer os.Remove(tempFilename)
- dsn := fmt.Sprintf("file:%s?cache=shared&mode=memory&_busy_timeout=%d", tempFilename, 500)
+ dsn := fmt.Sprintf("file:%s?cache=shared&mode=memory", tempFilename)
db, err := sql.Open("golite", dsn)
if err != nil {
t.Fatal("Failed to open database:", err)
@@ -1713,7 +1545,7 @@ func TestUnlockNotifyMany(t *testing.T) {
func TestUnlockNotifyDeadlock(t *testing.T) {
tempFilename := TempFilename(t)
defer os.Remove(tempFilename)
- dsn := fmt.Sprintf("file:%s?cache=shared&mode=memory&_busy_timeout=%d", tempFilename, 500)
+ dsn := fmt.Sprintf("file:%s?cache=shared&mode=memory", tempFilename)
db, err := sql.Open("golite", dsn)
if err != nil {
t.Fatal("Failed to open database:", err)
@@ -1833,31 +1665,6 @@ func doTestOpen(t *testing.T, url string) (string, error) {
return "", nil
}
-func TestOpen(t *testing.T) {
- cases := map[string]bool{
- "file:open1?mode=memory&cache=shared": true,
- "file:open1?mode=memory&cache=shared&_txlock=immediate": true,
- "file:open1?mode=memory&cache=shared&_txlock=deferred": true,
- "file:open1?mode=memory&cache=shared&_txlock=exclusive": true,
- "file:open1?mode=memory&cache=shared&_txlock=bogus": false,
- }
- for option, expectedPass := range cases {
- result, err := doTestOpen(t, option)
- if result == "" {
- if !expectedPass {
- errmsg := fmt.Sprintf("_txlock error not caught at dbOpen with option: %s", option)
- t.Fatal(errmsg)
- }
- } else if expectedPass {
- if err == nil {
- t.Fatal(result)
- } else {
- t.Fatal(result, err)
- }
- }
- }
-}
-
func TestOpenWithVFS(t *testing.T) {
{
uri := fmt.Sprintf("file:%s?mode=memory&vfs=hello", t.Name())
@@ -2004,35 +1811,6 @@ func TestDeferredForeignKey(t *testing.T) {
os.Remove(fname)
}
-func TestRecursiveTriggers(t *testing.T) {
- cases := map[string]bool{
- "?_recursive_triggers=1": true,
- "?_recursive_triggers=0": false,
- }
- for option, want := range cases {
- fname := TempFilename(t)
- uri := "file:" + fname + option + "&mode=memory"
- db, err := sql.Open("golite", uri)
- if err != nil {
- os.Remove(fname)
- t.Errorf("sql.Open(\"sqlite3\", %q): %v", uri, err)
- continue
- }
- var enabled bool
- err = db.QueryRow("PRAGMA recursive_triggers;").Scan(&enabled)
- db.Close()
- os.Remove(fname)
- if err != nil {
- t.Errorf("query recursive_triggers for %s: %v", uri, err)
- continue
- }
- if enabled != want {
- t.Errorf("\"PRAGMA recursive_triggers;\" for %q = %t; want %t", uri, enabled, want)
- continue
- }
- }
-}
-
func TestClose(t *testing.T) {
db, err := sql.Open("golite", ":memory:")
if err != nil {
@@ -2630,12 +2408,6 @@ func TestWAL(t *testing.T) {
}
defer db.Close()
- if _, err = db.Exec("PRAGMA journal_mode=WAL;"); err != nil {
- t.Fatal("Failed to Exec PRAGMA journal_mode:", err)
- }
- if _, err = db.Exec("PRAGMA locking_mode=EXCLUSIVE;"); err != nil {
- t.Fatal("Failed to Exec PRAGMA locking_mode:", err)
- }
if _, err = db.Exec("CREATE TABLE test (id SERIAL, user TEXT NOT NULL, name TEXT NOT NULL);"); err != nil {
t.Fatal("Failed to Exec CREATE TABLE:", err)
}
@@ -3371,10 +3143,7 @@ func TestSetFileControlInt(t *testing.T) {
}
defer db.Close()
- // Set to WAL mode & write a page.
- if _, err := db.Exec(`PRAGMA journal_mode = wal`); err != nil {
- t.Fatal("Failed to set journal mode:", err)
- } else if _, err := db.Exec(`CREATE TABLE t (x)`); err != nil {
+ if _, err := db.Exec(`CREATE TABLE t (x)`); err != nil {
t.Fatal("Failed to create table:", err)
}
if err := db.Close(); err != nil {
@@ -3544,7 +3313,7 @@ var tdb *TestDB
func initializeTestDB(t testing.TB) {
tempFilename := TempFilename(t)
- d, err := sql.Open("golite", tempFilename+"?_busy_timeout=99999&mode=memory&cache=shared")
+ d, err := sql.Open("golite", tempFilename+"?mode=memory&cache=shared")
if err != nil {
os.Remove(tempFilename)
t.Fatal(err)
@@ -3862,19 +3631,16 @@ func MainTest() {
{ "TestQueryRowContextCancel", TestQueryRowContextCancel },
{ "TestQueryRowContextCancelParallel", TestQueryRowContextCancelParallel },
{ "TestExecCancel", TestExecCancel },
- { "TestOpenContext", TestOpenContext },
{ "TestFileCopyTruncate", TestFileCopyTruncate },
{ "TestColumnTableName", TestColumnTableName },
{ "TestFTS3", TestFTS3 },
{ "TestFTS4", TestFTS4 },
{ "TestMathFunctions", TestMathFunctions },
{ "TestSerializeDeserialize", TestSerializeDeserialize },
- { "TestOpen", TestOpen },
{ "TestOpenWithVFS", TestOpenWithVFS },
{ "TestOpenNoCreate", TestOpenNoCreate },
{ "TestReadonly", TestReadonly },
{ "TestDeferredForeignKey", TestDeferredForeignKey },
- { "TestRecursiveTriggers", TestRecursiveTriggers },
{ "TestClose", TestClose },
{ "TestInsert", TestInsert },
{ "TestUpsert", TestUpsert },