Skip to content

Commit

Permalink
improve unit testing case for package gdb
Browse files Browse the repository at this point in the history
  • Loading branch information
gqcn committed Aug 27, 2021
1 parent b5502c5 commit 549adf6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
3 changes: 1 addition & 2 deletions database/gdb/gdb_driver_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
17 changes: 15 additions & 2 deletions database/gdb/gdb_z_mysql_basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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))
})
}
14 changes: 0 additions & 14 deletions database/gdb/gdb_z_mysql_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 549adf6

Please sign in to comment.