Add Tests

* Add TestTransactionConn

#598
This commit is contained in:
Gert-Jan Timmer 2018-06-27 16:43:15 +02:00
parent 283f0f8809
commit ded182737b
1 changed files with 36 additions and 0 deletions

View File

@ -9,6 +9,7 @@ package sqlite3
import (
"database/sql"
"fmt"
"os"
"testing"
)
@ -71,3 +72,38 @@ func TestTransaction(t *testing.T) {
t.Fatal("Expected failure to query")
}
}
func TestTransactionConn(t *testing.T) {
tempFilename := TempFilename(t)
defer os.Remove(tempFilename)
driverName := fmt.Sprintf("sqlite3.%s", t.Name())
// The driver's connection will be needed in order to perform the backup.
var dbConn *SQLiteConn
sql.Register(driverName, &SQLiteDriver{
ConnectHook: func(conn *SQLiteConn) error {
dbConn = conn
return nil
},
})
db, err := sql.Open(driverName, tempFilename)
if err != nil {
t.Fatal("Failed to open database:", err)
}
defer db.Close()
_, err = db.Exec("CREATE TABLE foo(id INTEGER)")
if err != nil {
t.Fatal("Failed to create table:", err)
}
tx, err := dbConn.Begin()
if err != nil {
t.Fatal(err)
}
if tx == nil {
t.Fatal("Failed to create Transaction")
}
}