From 321d10b67b7218c5cf3bebc0c01fc8c4536c2bc7 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Fri, 24 Jun 2016 07:48:03 +0800 Subject: [PATCH] Fix broken tests for postgres --- scaner_test.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/scaner_test.go b/scaner_test.go index 21410548..cd89ca49 100644 --- a/scaner_test.go +++ b/scaner_test.go @@ -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") + } }