Commit 1b69d19a authored by Daniel Theophanes's avatar Daniel Theophanes

database/sql: fix TestConversions when count > 1

Provide a fresh conversion table for TestConversions as it gets
modified on each test.

Change-Id: I6e2240d0c3455451271a6879e994b82222c3d44c
Reviewed-on: https://go-review.googlesource.com/89595
Run-TryBot: Daniel Theophanes <kardianos@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent e72e69a3
...@@ -64,7 +64,9 @@ var ( ...@@ -64,7 +64,9 @@ var (
scaniface interface{} scaniface interface{}
) )
var conversionTests = []conversionTest{ func conversionTests() []conversionTest {
// Return a fresh instance to test so "go test -count 2" works correctly.
return []conversionTest{
// Exact conversions (destination pointer type matches source type) // Exact conversions (destination pointer type matches source type)
{s: "foo", d: &scanstr, wantstr: "foo"}, {s: "foo", d: &scanstr, wantstr: "foo"},
{s: 123, d: &scanint, wantint: 123}, {s: 123, d: &scanint, wantint: 123},
...@@ -183,6 +185,7 @@ var conversionTests = []conversionTest{ ...@@ -183,6 +185,7 @@ var conversionTests = []conversionTest{
// Other errors // Other errors
{s: complex(1, 2), d: &scanstr, wanterr: `unsupported Scan, storing driver.Value type complex128 into type *string`}, {s: complex(1, 2), d: &scanstr, wanterr: `unsupported Scan, storing driver.Value type complex128 into type *string`},
}
} }
func intPtrValue(intptr interface{}) interface{} { func intPtrValue(intptr interface{}) interface{} {
...@@ -210,7 +213,7 @@ func timeValue(ptr interface{}) time.Time { ...@@ -210,7 +213,7 @@ func timeValue(ptr interface{}) time.Time {
} }
func TestConversions(t *testing.T) { func TestConversions(t *testing.T) {
for n, ct := range conversionTests { for n, ct := range conversionTests() {
err := convertAssign(ct.d, ct.s) err := convertAssign(ct.d, ct.s)
errstr := "" errstr := ""
if err != nil { if err != nil {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment