improve unit testing case for package gdb

This commit is contained in:
John Guo
2021-08-27 20:35:35 +08:00
parent b5502c5580
commit 549adf6487
3 changed files with 16 additions and 18 deletions

View File

@ -11,12 +11,11 @@ import (
"database/sql"
"fmt"
"github.com/gogf/gf/errors/gcode"
"net/url"
"github.com/gogf/gf/errors/gerror"
"github.com/gogf/gf/internal/intlog"
"github.com/gogf/gf/text/gregex"
"github.com/gogf/gf/text/gstr"
"net/url"
_ "github.com/go-sql-driver/mysql"
)

View File

@ -7,10 +7,10 @@
package gdb_test
import (
"testing"
"github.com/go-sql-driver/mysql"
"github.com/gogf/gf/database/gdb"
"github.com/gogf/gf/test/gtest"
"testing"
)
func Test_Instance(t *testing.T) {
@ -27,3 +27,16 @@ func Test_Instance(t *testing.T) {
t.Assert(err2, nil)
})
}
// Fix issue: https://github.com/gogf/gf/issues/819
func Test_Func_ConvertDataForTableRecord(t *testing.T) {
type Test struct {
ResetPasswordTokenAt mysql.NullTime `orm:"reset_password_token_at"`
}
gtest.C(t, func(t *gtest.T) {
m := gdb.ConvertDataForTableRecord(new(Test))
t.Assert(len(m), 1)
t.AssertNE(m["reset_password_token_at"], nil)
t.Assert(m["reset_password_token_at"], new(mysql.NullTime))
})
}

View File

@ -12,7 +12,6 @@ import (
"github.com/gogf/gf/os/gcmd"
"github.com/gogf/gf/os/gtime"
"github.com/gogf/gf/test/gtest"
"github.com/go-sql-driver/mysql"
"testing"
)
@ -292,19 +291,6 @@ CREATE TABLE %s (
})
}
// Fix issue: https://github.com/gogf/gf/issues/819
func Test_Func_ConvertDataForTableRecord(t *testing.T) {
type Test struct {
ResetPasswordTokenAt mysql.NullTime `orm:"reset_password_token_at"`
}
gtest.C(t, func(t *gtest.T) {
m := ConvertDataForTableRecord(new(Test))
t.Assert(len(m), 1)
t.AssertNE(m["reset_password_token_at"], nil)
t.Assert(m["reset_password_token_at"], new(mysql.NullTime))
})
}
func Test_isSubQuery(t *testing.T) {
gtest.C(t, func(t *gtest.T) {
t.Assert(isSubQuery("user"), false)