From 53a76f31b4f290f7a4d6f587723ae6817afda0de Mon Sep 17 00:00:00 2001 From: go-jet Date: Fri, 18 Oct 2019 09:56:38 +0200 Subject: [PATCH] Additional qrm tests. --- .circleci/config.yml | 2 +- qrm/utill.go | 9 ++------- qrm/utill_test.go | 35 +++++++++++++++++++++++++++++++++++ tests/testdata | 2 +- 4 files changed, 39 insertions(+), 9 deletions(-) create mode 100644 qrm/utill_test.go diff --git a/.circleci/config.yml b/.circleci/config.yml index 6c73d31..d3ea5d0 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -94,7 +94,7 @@ jobs: - run: mkdir -p $TEST_RESULTS - - run: go test -v ./... -coverpkg=github.com/go-jet/jet/postgres/...,github.com/go-jet/jet/mysql/...,github.com/go-jet/jet/execution/...,github.com/go-jet/jet/generator/...,github.com/go-jet/jet/internal/... -coverprofile=cover.out 2>&1 | go-junit-report > $TEST_RESULTS/results.xml + - run: go test -v ./... -coverpkg=github.com/go-jet/jet/postgres/...,github.com/go-jet/jet/mysql/...,github.com/go-jet/jet/qrm/...,github.com/go-jet/jet/generator/...,github.com/go-jet/jet/internal/... -coverprofile=cover.out 2>&1 | go-junit-report > $TEST_RESULTS/results.xml - run: name: Upload code coverage diff --git a/qrm/utill.go b/qrm/utill.go index baee26e..20b8b54 100644 --- a/qrm/utill.go +++ b/qrm/utill.go @@ -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 { diff --git a/qrm/utill_test.go b/qrm/utill_test.go new file mode 100644 index 0000000..e4ab53d --- /dev/null +++ b/qrm/utill_test.go @@ -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) +} diff --git a/tests/testdata b/tests/testdata index 1f6bd8b..02e0795 160000 --- a/tests/testdata +++ b/tests/testdata @@ -1 +1 @@ -Subproject commit 1f6bd8bb86458019fa43b1e2cd7ae9488a7ac9a4 +Subproject commit 02e0795d1e06b959d0c564dc1e349159d57b1bf6