mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
database/sql: make TestDrivers not crash on second run
Using -test.cpu=1,1 made it crash before. Fixes #9024 LGTM=iant R=adg, iant CC=golang-codereviews https://golang.org/cl/169860043
This commit is contained in:
parent
2074046d00
commit
9dc1cce38d
2 changed files with 7 additions and 0 deletions
|
|
@ -141,6 +141,8 @@ type Dummy struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDrivers(t *testing.T) {
|
func TestDrivers(t *testing.T) {
|
||||||
|
unregisterAllDrivers()
|
||||||
|
Register("test", fdriver)
|
||||||
Register("invalid", Dummy{})
|
Register("invalid", Dummy{})
|
||||||
all := Drivers()
|
all := Drivers()
|
||||||
if len(all) < 2 || !sort.StringsAreSorted(all) || !contains(all, "test") || !contains(all, "invalid") {
|
if len(all) < 2 || !sort.StringsAreSorted(all) || !contains(all, "test") || !contains(all, "invalid") {
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,11 @@ func Register(name string, driver driver.Driver) {
|
||||||
drivers[name] = driver
|
drivers[name] = driver
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func unregisterAllDrivers() {
|
||||||
|
// For tests.
|
||||||
|
drivers = make(map[string]driver.Driver)
|
||||||
|
}
|
||||||
|
|
||||||
// Drivers returns a sorted list of the names of the registered drivers.
|
// Drivers returns a sorted list of the names of the registered drivers.
|
||||||
func Drivers() []string {
|
func Drivers() []string {
|
||||||
var list []string
|
var list []string
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue