Skip to content

Commit e941c93

Browse files
committed
trying to get more information out of Travis II
1 parent ec804a3 commit e941c93

File tree

2 files changed

+51
-23
lines changed

2 files changed

+51
-23
lines changed

driver_test.go

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,37 @@ type timeTest struct {
338338
t time.Time
339339
}
340340

341-
func (t timeTest) genQuery(dbtype string, binaryProtocol bool) string {
341+
type timeMode byte
342+
343+
func (t timeMode) String() string {
344+
switch t {
345+
case binaryString:
346+
return "binary:string"
347+
case binaryTime:
348+
return "binary:time.Time"
349+
case textString:
350+
return "text:string"
351+
}
352+
panic("unsupported timeMode")
353+
}
354+
355+
func (t timeMode) Binary() bool {
356+
switch t {
357+
case binaryString, binaryTime:
358+
return true
359+
}
360+
return false
361+
}
362+
363+
const (
364+
binaryString timeMode = iota
365+
binaryTime
366+
textString
367+
)
368+
369+
func (t timeTest) genQuery(dbtype string, mode timeMode) string {
342370
var inner string
343-
if binaryProtocol {
371+
if mode.Binary() {
344372
inner = "?"
345373
} else {
346374
inner = `"%s"`
@@ -351,17 +379,15 @@ func (t timeTest) genQuery(dbtype string, binaryProtocol bool) string {
351379
return `SELECT CAST(` + inner + ` AS ` + dbtype + `)`
352380
}
353381

354-
func (t timeTest) run(dbt *DBTest, dbtype, tlayout string, mode int) {
382+
func (t timeTest) run(dbt *DBTest, dbtype, tlayout string, mode timeMode) {
355383
var rows *sql.Rows
356-
query := t.genQuery(dbtype, mode < 2)
357-
var protocol = "binary"
384+
query := t.genQuery(dbtype, mode)
358385
switch mode {
359-
case 0:
386+
case binaryString:
360387
rows = dbt.mustQuery(query, t.s)
361-
case 1:
388+
case binaryTime:
362389
rows = dbt.mustQuery(query, t.t)
363-
case 2:
364-
protocol = "text"
390+
case textString:
365391
query = fmt.Sprintf(query, t.s)
366392
rows = dbt.mustQuery(query)
367393
default:
@@ -374,13 +400,13 @@ func (t timeTest) run(dbt *DBTest, dbtype, tlayout string, mode int) {
374400
if err == nil {
375401
err = fmt.Errorf("no data")
376402
}
377-
dbt.Errorf("%s [%s]: %s", dbtype, protocol, err)
403+
dbt.Errorf("%s [%s]: %s", dbtype, mode, err)
378404
return
379405
}
380406
var dst interface{}
381407
err = rows.Scan(&dst)
382408
if err != nil {
383-
dbt.Errorf("%s [%s]: %s", dbtype, protocol, err)
409+
dbt.Errorf("%s [%s]: %s", dbtype, mode, err)
384410
return
385411
}
386412
switch val := dst.(type) {
@@ -389,22 +415,22 @@ func (t timeTest) run(dbt *DBTest, dbtype, tlayout string, mode int) {
389415
if str == t.s {
390416
return
391417
}
392-
dbt.Errorf("%s to string [%s]: expected %q, got %q",
393-
dbtype, protocol,
418+
dbt.Errorf("%s [%s] to string: expected %q, got %q",
419+
dbtype, mode,
394420
t.s, str,
395421
)
396422
case time.Time:
397423
if val == t.t {
398424
return
399425
}
400-
dbt.Errorf("%s to string [%s]: expected %q, got %q",
401-
dbtype, protocol,
426+
dbt.Errorf("%s [%s] to string: expected %q, got %q",
427+
dbtype, mode,
402428
t.s, val.Format(tlayout),
403429
)
404430
default:
405431
fmt.Printf("%#v\n", []interface{}{dbtype, tlayout, mode, t.s, t.t})
406432
dbt.Errorf("%s [%s]: unhandled type %T (is '%v')",
407-
dbtype, protocol,
433+
dbtype, mode,
408434
val, val,
409435
)
410436
}
@@ -514,25 +540,25 @@ func TestDateTime(t *testing.T) {
514540
continue
515541
}
516542
for _, setup := range setups.tests {
517-
timeArgBinary := true
543+
allowBinTime := true
518544
if setup.s == "" {
519545
// fill time string whereever Go can reliable produce it
520546
setup.s = setup.t.Format(setups.tlayout)
521547
} else if setup.s[0] == '!' {
522548
// skip tests using setup.t as source in queries
523-
timeArgBinary = false
549+
allowBinTime = false
524550
// fix setup.s - remove the "!"
525551
setup.s = setup.s[1:]
526552
}
527553
if !allowsZero && setup.s == tstr0[:len(setup.s)] {
528554
// skip disallowed 0000-00-00 date
529555
continue
530556
}
531-
setup.run(dbt, setups.dbtype, setups.tlayout, 0)
532-
if timeArgBinary {
533-
setup.run(dbt, setups.dbtype, setups.tlayout, 1)
557+
setup.run(dbt, setups.dbtype, setups.tlayout, textString)
558+
setup.run(dbt, setups.dbtype, setups.tlayout, binaryString)
559+
if allowBinTime {
560+
setup.run(dbt, setups.dbtype, setups.tlayout, binaryTime)
534561
}
535-
setup.run(dbt, setups.dbtype, setups.tlayout, 2)
536562
}
537563
}
538564
})

packets.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,9 @@ func (rows *binaryRows) readRow(dest []driver.Value) error {
10941094
case 1, 2, 3, 4, 5, 6:
10951095
dstlen = 19 + 1 + decimals
10961096
default:
1097-
panic(fmt.Sprintf("%#v", rows.columns[i]))
1097+
panic(fmt.Sprintf("unexpected decimals value in column %d: %#v",
1098+
i, rows.columns[i],
1099+
))
10981100
}
10991101
}
11001102
dest[i], err = formatBinaryDateTime(data[pos:pos+int(num)], dstlen, false)

0 commit comments

Comments
 (0)