aboutsummaryrefslogtreecommitdiff
path: root/src/database/sql/sql_test.go
diff options
context:
space:
mode:
authorJames Lawrence <jljatone@gmail.com>2017-08-05 06:04:19 -0400
committerDaniel Theophanes <kardianos@gmail.com>2017-09-23 20:47:06 +0000
commite6358c798b3001e98b6f7f4c3e2d906cf48533b2 (patch)
tree2cccc26a32cc67e720372a67423c7418f4382c5d /src/database/sql/sql_test.go
parent6936671ed1c3a1dd25e0eea635ee2bdc86acd463 (diff)
downloadgo-e6358c798b3001e98b6f7f4c3e2d906cf48533b2.tar.xz
database/sql: add OpenDB to directly create a *DB without a DSN.
The current Open method limits the ability for driver maintainers to expose options for their drivers by forcing all the configuration to pass through the DSN in order to create a *DB. This CL allows driver maintainers to write their own initialization functions that return a *DB making configuration of the underlying drivers easier. Fixes #20268 Change-Id: Ib10b794f36a201bbb92c23999c8351815d38eedb Reviewed-on: https://go-review.googlesource.com/53430 Reviewed-by: Daniel Theophanes <kardianos@gmail.com> Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/database/sql/sql_test.go')
-rw-r--r--src/database/sql/sql_test.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/database/sql/sql_test.go b/src/database/sql/sql_test.go
index bcf0887d0e..fe7c3278c7 100644
--- a/src/database/sql/sql_test.go
+++ b/src/database/sql/sql_test.go
@@ -81,6 +81,13 @@ func newTestDB(t testing.TB, name string) *DB {
return db
}
+func TestOpenDB(t *testing.T) {
+ db := OpenDB(dsnConnector{dsn: fakeDBName, driver: fdriver})
+ if db.Driver() != fdriver {
+ t.Fatalf("OpenDB should return the driver of the Connector")
+ }
+}
+
func TestDriverPanic(t *testing.T) {
// Test that if driver panics, database/sql does not deadlock.
db, err := Open("test", fakeDBName)
@@ -1672,7 +1679,7 @@ func TestIssue4902(t *testing.T) {
db := newTestDB(t, "people")
defer closeDB(t, db)
- driver := db.driver.(*fakeDriver)
+ driver := db.Driver().(*fakeDriver)
opens0 := driver.openCount
var stmt *Stmt
@@ -1765,7 +1772,7 @@ func TestMaxOpenConns(t *testing.T) {
db := newTestDB(t, "magicquery")
defer closeDB(t, db)
- driver := db.driver.(*fakeDriver)
+ driver := db.Driver().(*fakeDriver)
// Force the number of open connections to 0 so we can get an accurate
// count for the test
@@ -2057,7 +2064,7 @@ func TestConnMaxLifetime(t *testing.T) {
db := newTestDB(t, "magicquery")
defer closeDB(t, db)
- driver := db.driver.(*fakeDriver)
+ driver := db.Driver().(*fakeDriver)
// Force the number of open connections to 0 so we can get an accurate
// count for the test
@@ -2146,7 +2153,7 @@ func TestStmtCloseDeps(t *testing.T) {
db := newTestDB(t, "magicquery")
defer closeDB(t, db)
- driver := db.driver.(*fakeDriver)
+ driver := db.Driver().(*fakeDriver)
driver.mu.Lock()
opens0 := driver.openCount
@@ -3071,7 +3078,7 @@ func TestIssue6081(t *testing.T) {
db := newTestDB(t, "people")
defer closeDB(t, db)
- drv := db.driver.(*fakeDriver)
+ drv := db.Driver().(*fakeDriver)
drv.mu.Lock()
opens0 := drv.openCount
closes0 := drv.closeCount
@@ -3326,7 +3333,7 @@ func TestConnectionLeak(t *testing.T) {
// Now we have defaultMaxIdleConns busy connections. Open
// a new one, but wait until the busy connections are released
// before returning control to DB.
- drv := db.driver.(*fakeDriver)
+ drv := db.Driver().(*fakeDriver)
drv.waitCh = make(chan struct{}, 1)
drv.waitingCh = make(chan struct{}, 1)
var wg sync.WaitGroup