@@ -106,7 +106,7 @@ type DBTest struct {
106
106
db * sql.DB
107
107
}
108
108
109
- func runTests (t * testing.T , name string , tests ... func (dbt * DBTest )) {
109
+ func runTests (t * testing.T , name , dsn string , tests ... func (dbt * DBTest )) {
110
110
if ! available {
111
111
t .Logf ("MySQL-Server not running on %s. Skipping %s" , netAddr , name )
112
112
return
@@ -151,7 +151,7 @@ func (dbt *DBTest) mustQuery(query string, args ...interface{}) (rows *sql.Rows)
151
151
}
152
152
153
153
func TestRawBytesResultExceedsBuffer (t * testing.T ) {
154
- runTests (t , "TestRawBytesResultExceedsBuffer" , func (dbt * DBTest ) {
154
+ runTests (t , "TestRawBytesResultExceedsBuffer" , dsn , func (dbt * DBTest ) {
155
155
// defaultBufSize from buffer.go
156
156
expected := strings .Repeat ("abc" , defaultBufSize )
157
157
rows := dbt .mustQuery ("SELECT '" + expected + "'" )
@@ -168,7 +168,7 @@ func TestRawBytesResultExceedsBuffer(t *testing.T) {
168
168
}
169
169
170
170
func TestCRUD (t * testing.T ) {
171
- runTests (t , "TestCRUD" , func (dbt * DBTest ) {
171
+ runTests (t , "TestCRUD" , dsn , func (dbt * DBTest ) {
172
172
// Create Table
173
173
dbt .mustExec ("CREATE TABLE test (value BOOL)" )
174
174
@@ -260,7 +260,7 @@ func TestCRUD(t *testing.T) {
260
260
}
261
261
262
262
func TestInt (t * testing.T ) {
263
- runTests (t , "TestInt" , func (dbt * DBTest ) {
263
+ runTests (t , "TestInt" , dsn , func (dbt * DBTest ) {
264
264
types := [5 ]string {"TINYINT" , "SMALLINT" , "MEDIUMINT" , "INT" , "BIGINT" }
265
265
in := int64 (42 )
266
266
var out int64
@@ -307,7 +307,7 @@ func TestInt(t *testing.T) {
307
307
}
308
308
309
309
func TestFloat (t * testing.T ) {
310
- runTests (t , "TestFloat" , func (dbt * DBTest ) {
310
+ runTests (t , "TestFloat" , dsn , func (dbt * DBTest ) {
311
311
types := [2 ]string {"FLOAT" , "DOUBLE" }
312
312
in := float32 (42.23 )
313
313
var out float32
@@ -330,7 +330,7 @@ func TestFloat(t *testing.T) {
330
330
}
331
331
332
332
func TestString (t * testing.T ) {
333
- runTests (t , "TestString" , func (dbt * DBTest ) {
333
+ runTests (t , "TestString" , dsn , func (dbt * DBTest ) {
334
334
types := [6 ]string {"CHAR(255)" , "VARCHAR(255)" , "TINYTEXT" , "TEXT" , "MEDIUMTEXT" , "LONGTEXT" }
335
335
in := "κόσμε üöäßñóùéàâÿœ'îë Árvíztűrő いろはにほへとちりぬるを イロハニホヘト דג סקרן чащах น่าฟังเอย"
336
336
var out string
@@ -470,18 +470,15 @@ func TestDateTime(t *testing.T) {
470
470
}
471
471
}
472
472
473
- oldDsn := dsn
474
- usedDsn := oldDsn + "&sql_mode=ALLOW_INVALID_DATES"
473
+ timeDsn := dsn + "&sql_mode=ALLOW_INVALID_DATES"
475
474
for _ , v := range setups {
476
475
s = v
477
- dsn = usedDsn + s .dsnSuffix
478
- runTests (t , "TestDateTime" , testTime )
476
+ runTests (t , "TestDateTime" , timeDsn + s .dsnSuffix , testTime )
479
477
}
480
- dsn = oldDsn
481
478
}
482
479
483
480
func TestNULL (t * testing.T ) {
484
- runTests (t , "TestNULL" , func (dbt * DBTest ) {
481
+ runTests (t , "TestNULL" , dsn , func (dbt * DBTest ) {
485
482
nullStmt , err := dbt .db .Prepare ("SELECT NULL" )
486
483
if err != nil {
487
484
dbt .Fatal (err )
@@ -597,7 +594,7 @@ func TestNULL(t *testing.T) {
597
594
}
598
595
599
596
func TestLongData (t * testing.T ) {
600
- runTests (t , "TestLongData" , func (dbt * DBTest ) {
597
+ runTests (t , "TestLongData" , dsn , func (dbt * DBTest ) {
601
598
var maxAllowedPacketSize int
602
599
err := dbt .db .QueryRow ("select @@max_allowed_packet" ).Scan (& maxAllowedPacketSize )
603
600
if err != nil {
@@ -654,7 +651,7 @@ func TestLongData(t *testing.T) {
654
651
}
655
652
656
653
func TestLoadData (t * testing.T ) {
657
- runTests (t , "TestLoadData" , func (dbt * DBTest ) {
654
+ runTests (t , "TestLoadData" , dsn , func (dbt * DBTest ) {
658
655
verifyLoadDataResult := func () {
659
656
rows , err := dbt .db .Query ("SELECT * FROM test" )
660
657
if err != nil {
@@ -741,10 +738,9 @@ func TestLoadData(t *testing.T) {
741
738
}
742
739
743
740
func TestStrict (t * testing.T ) {
744
- oldDsn := dsn
745
- // to get rid of stricter modes - we want to test for warnings, not errors
746
- dsn += "&sql_mode=ALLOW_INVALID_DATES"
747
- runTests (t , "TestStrict" , func (dbt * DBTest ) {
741
+ // ALLOW_INVALID_DATES to get rid of stricter modes - we want to test for warnings, not errors
742
+ relaxedDsn := dsn + "&sql_mode=ALLOW_INVALID_DATES"
743
+ runTests (t , "TestStrict" , relaxedDsn , func (dbt * DBTest ) {
748
744
dbt .mustExec ("CREATE TABLE test (a TINYINT NOT NULL, b CHAR(4))" )
749
745
750
746
var queries = [... ]struct {
@@ -806,13 +802,12 @@ func TestStrict(t *testing.T) {
806
802
}
807
803
}
808
804
})
809
- dsn = oldDsn
810
805
}
811
806
812
807
// Special cases
813
808
814
809
func TestRowsClose (t * testing.T ) {
815
- runTests (t , "TestRowsClose" , func (dbt * DBTest ) {
810
+ runTests (t , "TestRowsClose" , dsn , func (dbt * DBTest ) {
816
811
rows , err := dbt .db .Query ("SELECT 1" )
817
812
if err != nil {
818
813
dbt .Fatal (err )
@@ -837,7 +832,7 @@ func TestRowsClose(t *testing.T) {
837
832
// dangling statements
838
833
// http://code.google.com/p/go/issues/detail?id=3865
839
834
func TestCloseStmtBeforeRows (t * testing.T ) {
840
- runTests (t , "TestCloseStmtBeforeRows" , func (dbt * DBTest ) {
835
+ runTests (t , "TestCloseStmtBeforeRows" , dsn , func (dbt * DBTest ) {
841
836
stmt , err := dbt .db .Prepare ("SELECT 1" )
842
837
if err != nil {
843
838
dbt .Fatal (err )
@@ -878,7 +873,7 @@ func TestCloseStmtBeforeRows(t *testing.T) {
878
873
// It is valid to have multiple Rows for the same Stmt
879
874
// http://code.google.com/p/go/issues/detail?id=3734
880
875
func TestStmtMultiRows (t * testing.T ) {
881
- runTests (t , "TestStmtMultiRows" , func (dbt * DBTest ) {
876
+ runTests (t , "TestStmtMultiRows" , dsn , func (dbt * DBTest ) {
882
877
stmt , err := dbt .db .Prepare ("SELECT 1 UNION SELECT 0" )
883
878
if err != nil {
884
879
dbt .Fatal (err )
@@ -993,7 +988,7 @@ func TestConcurrent(t *testing.T) {
993
988
t .Log ("CONCURRENT env var not set. Skipping TestConcurrent" )
994
989
return
995
990
}
996
- runTests (t , "TestConcurrent" , func (dbt * DBTest ) {
991
+ runTests (t , "TestConcurrent" , dsn , func (dbt * DBTest ) {
997
992
var max int
998
993
err := dbt .db .QueryRow ("SELECT @@max_connections" ).Scan (& max )
999
994
if err != nil {
0 commit comments