Test no setter generated
package resource_test
import (
+ "database/sql/driver"
"fmt"
"reflect"
"testing"
@@ -29,6 +30,7 @@ func checkMeta(record interface{}, meta *resource.Meta, value interface{}, t *te
meta.PreInitialize()
meta.Initialize()
+ if meta.Setter != nil {
meta.Setter(record, metaValue, context)
if context.HasError() {
t.Errorf("No error should happen, but got %v", context.Errors)
@@ -37,6 +39,9 @@ func checkMeta(record interface{}, meta *resource.Meta, value interface{}, t *te
if result := meta.Valuer(record, context); format(result) != expectedValue {
t.Errorf("Wrong value, should be %v, but got %v", expectedValue, format(result))
}
+ } else {
+ t.Errorf("No setter generated for meta %v", meta.Name)
+ }
}
func TestStringMetaValuerAndSetter(t *testing.T) {
@@ -161,6 +166,33 @@ func TestBoolMetaValuerAndSetter(t *testing.T) {
checkMeta(&user, meta4, "f", t, "false")
}
+type scanner struct {
+ Body string
+}
+
+func (s *scanner) Scan(value interface{}) {
+ s.Body = fmt.Sprint(value)
+}
+
+func (s *scanner) Value() (driver.Value, error) {
+ return s.Body, nil
+}
+
+func TestScannerMetaValuerAndSetter(t *testing.T) {
+ user := &struct {
+ Scanner scanner
+ }{}
+
+ res := resource.New(&user)
+
+ meta := &resource.Meta{
+ Name: "Scanner",
+ BaseResource: res,
+ }
+
+ checkMeta(&user, meta, "scanner", t)
+}
+
func TestSliceMetaValuerAndSetter(t *testing.T) {
t.Skip()
