fix tests of query interface

This commit is contained in:
Lunny Xiao 2017-08-27 21:56:08 +08:00
parent 586ee973d6
commit e9d2e9e693
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
1 changed files with 30 additions and 3 deletions

View File

@ -6,6 +6,7 @@ package xorm
import (
"fmt"
"strconv"
"testing"
"time"
@ -53,6 +54,32 @@ func toString(i interface{}) string {
return fmt.Sprintf("%v", i)
}
func toInt64(i interface{}) int64 {
switch i.(type) {
case []byte:
n, _ := strconv.ParseInt(string(i.([]byte)), 10, 64)
return n
case int:
return int64(i.(int))
case int64:
return i.(int64)
}
return 0
}
func toFloat64(i interface{}) float64 {
switch i.(type) {
case []byte:
n, _ := strconv.ParseFloat(string(i.([]byte)), 64)
return n
case float64:
return i.(float64)
case float32:
return float64(i.(float32))
}
return 0
}
func TestQueryInterface(t *testing.T) {
assert.NoError(t, prepareEngine())
@ -78,8 +105,8 @@ func TestQueryInterface(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, 1, len(records))
assert.Equal(t, 5, len(records[0]))
assert.EqualValues(t, 1, records[0]["id"])
assert.EqualValues(t, 1, toInt64(records[0]["id"]))
assert.Equal(t, "hi", toString(records[0]["msg"]))
assert.EqualValues(t, 28, records[0]["age"])
assert.EqualValues(t, 1.5, records[0]["money"])
assert.EqualValues(t, 28, toInt64(records[0]["age"]))
assert.EqualValues(t, 1.5, toFloat64(records[0]["money"]))
}