Fix broken tests for postgres

This commit is contained in:
Jinzhu 2016-06-24 07:48:03 +08:00
parent 1485f4bce9
commit 321d10b67b
1 changed files with 17 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package gorm_test
import (
"database/sql/driver"
"encoding/json"
"errors"
"testing"
)
@ -51,7 +52,14 @@ func (l ExampleStringSlice) Value() (driver.Value, error) {
}
func (l *ExampleStringSlice) Scan(input interface{}) error {
return json.Unmarshal(input.([]byte), l)
switch value := input.(type) {
case string:
return json.Unmarshal([]byte(value), l)
case []byte:
return json.Unmarshal(value, l)
default:
return errors.New("not supported")
}
}
type ExampleStruct struct {
@ -66,5 +74,12 @@ func (l ExampleStructSlice) Value() (driver.Value, error) {
}
func (l *ExampleStructSlice) Scan(input interface{}) error {
return json.Unmarshal(input.([]byte), l)
switch value := input.(type) {
case string:
return json.Unmarshal([]byte(value), l)
case []byte:
return json.Unmarshal(value, l)
default:
return errors.New("not supported")
}
}