Additional qrm tests.
This commit is contained in:
parent
2891cc71be
commit
53a76f31b4
4 changed files with 39 additions and 9 deletions
|
|
@ -156,6 +156,7 @@ func valueToString(value reflect.Value) string {
|
|||
|
||||
var timeType = reflect.TypeOf(time.Now())
|
||||
var uuidType = reflect.TypeOf(uuid.New())
|
||||
var byteArrayType = reflect.TypeOf([]byte(""))
|
||||
|
||||
func isSimpleModelType(objType reflect.Type) bool {
|
||||
objType = indirectType(objType)
|
||||
|
|
@ -167,15 +168,9 @@ func isSimpleModelType(objType reflect.Type) bool {
|
|||
reflect.String,
|
||||
reflect.Bool:
|
||||
return true
|
||||
case reflect.Slice:
|
||||
return objType.Elem().Kind() == reflect.Uint8 //[]byte
|
||||
case reflect.Struct:
|
||||
return objType == timeType
|
||||
case reflect.Array:
|
||||
return objType == uuidType // uuid.UUID returns reflect.Array kind
|
||||
}
|
||||
|
||||
return false
|
||||
return objType == timeType || objType == uuidType || objType == byteArrayType
|
||||
}
|
||||
|
||||
func isIntegerType(value reflect.Type) bool {
|
||||
|
|
|
|||
35
qrm/utill_test.go
Normal file
35
qrm/utill_test.go
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
package qrm
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"gotest.tools/assert"
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestIsSimpleModelType(t *testing.T) {
|
||||
assert.Assert(t, isSimpleModelType(reflect.TypeOf(int8(11))))
|
||||
assert.Assert(t, isSimpleModelType(reflect.TypeOf(int16(11))))
|
||||
assert.Assert(t, isSimpleModelType(reflect.TypeOf(int32(11))))
|
||||
assert.Assert(t, isSimpleModelType(reflect.TypeOf(int64(11))))
|
||||
assert.Assert(t, isSimpleModelType(reflect.TypeOf(uint8(11))))
|
||||
assert.Assert(t, isSimpleModelType(reflect.TypeOf(uint16(11))))
|
||||
assert.Assert(t, isSimpleModelType(reflect.TypeOf(uint32(11))))
|
||||
assert.Assert(t, isSimpleModelType(reflect.TypeOf(uint64(11))))
|
||||
|
||||
assert.Assert(t, isSimpleModelType(reflect.TypeOf(float32(123.46))))
|
||||
assert.Assert(t, isSimpleModelType(reflect.TypeOf(float64(123.46))))
|
||||
|
||||
assert.Assert(t, isSimpleModelType(reflect.TypeOf([]byte("Text"))))
|
||||
assert.Assert(t, isSimpleModelType(reflect.TypeOf(time.Now())))
|
||||
assert.Assert(t, isSimpleModelType(reflect.TypeOf(uuid.New())))
|
||||
|
||||
complexModelType := struct {
|
||||
Field1 string
|
||||
Field2 string
|
||||
}{}
|
||||
|
||||
assert.Equal(t, isSimpleModelType(reflect.TypeOf(complexModelType)), false)
|
||||
assert.Equal(t, isSimpleModelType(reflect.TypeOf(&complexModelType)), false)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue