sqlite3_test.go: Move Go 1.13 test to sqlite3_go113_test.go (#883)

Commit 4f7abea96e added a test that uses Conn.Raw, which was added in
Go >= 1.13. The go-sqlite3 project runs tests with Go >= 1.11. Remove
the test from sqlite3_test.go, so it only runs with the correct
versions of Go.

Instead of adding a new test, modify the existing test that already
uses Conn.Raw() to check the type of driverConn.
move-code
Evan Jones 2020-11-16 11:52:26 -05:00 committed by GitHub
parent 4f7abea96e
commit 70c77097f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 31 deletions

2
doc.go
View File

@ -90,7 +90,7 @@ ConnectHook to get the SQLiteConn.
}, },
}) })
You can also use database/sql.Conn.Raw: You can also use database/sql.Conn.Raw (Go >= 1.13):
conn, err := db.Conn(context.Background()) conn, err := db.Conn(context.Background())
// if err != nil { ... } // if err != nil { ... }

View File

@ -49,6 +49,10 @@ func TestBeginTxCancel(t *testing.T) {
if !ok { if !ok {
t.Fatal("unexpected: wrong type") t.Fatal("unexpected: wrong type")
} }
// checks that conn.Raw can be used to get *SQLiteConn
if _, ok = driverConn.(*SQLiteConn); !ok {
t.Fatalf("conn.Raw() driverConn type=%T, expected *SQLiteConn", driverConn)
}
go cancel() // make it cancel concurrently with exec("BEGIN"); go cancel() // make it cancel concurrently with exec("BEGIN");
tx, err := d.BeginTx(ctx, driver.TxOptions{}) tx, err := d.BeginTx(ctx, driver.TxOptions{})

View File

@ -9,7 +9,6 @@ package sqlite3
import ( import (
"bytes" "bytes"
"context"
"database/sql" "database/sql"
"database/sql/driver" "database/sql/driver"
"errors" "errors"
@ -2353,32 +2352,3 @@ func benchmarkStmtRows(b *testing.B) {
} }
} }
} }
func TestConnRawIsSQLiteConn(t *testing.T) {
db, err := sql.Open("sqlite3", ":memory:")
if err != nil {
t.Fatal("Failed to open db:", err)
}
defer db.Close()
conn, err := db.Conn(context.Background())
if err != nil {
t.Fatal("Failed to get conn:", err)
}
defer conn.Close()
err = conn.Raw(func(driverConn interface{}) error {
sqliteConn, ok := driverConn.(*SQLiteConn)
if !ok {
t.Errorf("driverConn type=%T; expected to be *SQLiteConn", driverConn)
return nil
}
// call a private SQLite API to confirm the raw conn "works"
if sqliteConn.AuthEnabled() {
t.Error("sqliteConn.AuthEnabled()=true; expected false")
}
return nil
})
if err != nil {
t.Error("conn.Raw() returned err:", err)
}
}