aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-10-30 06:54:34 -0300
committerEuAndreh <eu@euandre.org>2024-10-30 06:54:34 -0300
commitb2e1a5ccae8e0f1f1c9ce00c0f5434924251e5ff (patch)
tree97f40468aab2750e78f4f2c50ed225b06e96a820 /tests
parent.gitignore: Normalize according to other go projects (diff)
downloadgolite-b2e1a5ccae8e0f1f1c9ce00c0f5434924251e5ff.tar.gz
golite-b2e1a5ccae8e0f1f1c9ce00c0f5434924251e5ff.tar.xz
src/golite.go: Use IMMEDIATE transaction for db.Begin()
Diffstat (limited to 'tests')
-rw-r--r--tests/golite.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/tests/golite.go b/tests/golite.go
index c51c1f3..2c7fe6c 100644
--- a/tests/golite.go
+++ b/tests/golite.go
@@ -54,6 +54,7 @@ func testBackup(t *testing.T, testRowCount int, usePerPageSteps bool) {
t.Fatal("Failed to open the source database:", err)
}
defer srcDb.Close()
+
err = srcDb.Ping()
if err != nil {
t.Fatal("Failed to connect to the source database:", err)
@@ -66,6 +67,7 @@ func testBackup(t *testing.T, testRowCount int, usePerPageSteps bool) {
t.Fatal("Failed to open the destination database:", err)
}
defer destDb.Close()
+
err = destDb.Ping()
if err != nil {
t.Fatal("Failed to connect to the destination database:", err)
@@ -75,10 +77,12 @@ func testBackup(t *testing.T, testRowCount int, usePerPageSteps bool) {
if len(driverConns) != 2 {
t.Fatalf("Expected 2 driver connections, but found %v.", len(driverConns))
}
+
srcDbDriverConn := driverConns[0]
if srcDbDriverConn == nil {
t.Fatal("The source database driver connection is nil.")
}
+
destDbDriverConn := driverConns[1]
if destDbDriverConn == nil {
t.Fatal("The destination database driver connection is nil.")
@@ -94,13 +98,15 @@ func testBackup(t *testing.T, testRowCount int, usePerPageSteps bool) {
if err != nil {
t.Fatal("Failed to begin a transaction when populating the source database:", err)
}
- _, err = srcDb.Exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)")
+
+ _, err = tx.Exec("CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT)")
if err != nil {
tx.Rollback()
t.Fatal("Failed to create the source database \"test\" table:", err)
}
+
for id := 0; id < testRowCount; id++ {
- _, err = srcDb.Exec("INSERT INTO test (id, value) VALUES (?, ?)", id, generateTestData(id))
+ _, err = tx.Exec("INSERT INTO test (id, value) VALUES (?, ?)", id, generateTestData(id))
if err != nil {
tx.Rollback()
t.Fatal("Failed to insert a row into the source database \"test\" table:", err)