2021-01-17 21:46:25 +08:00
|
|
|
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
2019-04-02 14:37:46 +08:00
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
|
|
|
|
package gdb_test
|
|
|
|
|
|
|
|
import (
|
2021-11-13 23:23:55 +08:00
|
|
|
"testing"
|
|
|
|
|
2021-08-27 20:35:35 +08:00
|
|
|
"github.com/go-sql-driver/mysql"
|
2021-11-16 17:21:13 +08:00
|
|
|
|
2021-10-11 21:41:56 +08:00
|
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
|
|
"github.com/gogf/gf/v2/test/gtest"
|
2019-04-02 14:37:46 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_Instance(t *testing.T) {
|
2020-03-19 22:56:12 +08:00
|
|
|
gtest.C(t, func(t *gtest.T) {
|
2019-06-19 09:06:52 +08:00
|
|
|
_, err := gdb.Instance("none")
|
2020-03-19 22:56:12 +08:00
|
|
|
t.AssertNE(err, nil)
|
2019-04-02 14:37:46 +08:00
|
|
|
|
2019-06-19 09:06:52 +08:00
|
|
|
db, err := gdb.Instance()
|
2021-02-07 14:39:32 +08:00
|
|
|
t.AssertNil(err)
|
2019-04-02 14:37:46 +08:00
|
|
|
|
2019-06-19 09:06:52 +08:00
|
|
|
err1 := db.PingMaster()
|
|
|
|
err2 := db.PingSlave()
|
2020-03-19 22:56:12 +08:00
|
|
|
t.Assert(err1, nil)
|
|
|
|
t.Assert(err2, nil)
|
2019-06-19 09:06:52 +08:00
|
|
|
})
|
2019-04-02 14:37:46 +08:00
|
|
|
}
|
2021-08-27 20:35:35 +08:00
|
|
|
|
|
|
|
// Fix issue: https://github.com/gogf/gf/issues/819
|
2021-12-23 22:00:28 +08:00
|
|
|
func Test_Func_ConvertDataForRecord(t *testing.T) {
|
2021-08-27 20:35:35 +08:00
|
|
|
type Test struct {
|
|
|
|
ResetPasswordTokenAt mysql.NullTime `orm:"reset_password_token_at"`
|
|
|
|
}
|
|
|
|
gtest.C(t, func(t *gtest.T) {
|
2021-12-23 22:00:28 +08:00
|
|
|
c := &gdb.Core{}
|
|
|
|
m := c.ConvertDataForRecord(nil, new(Test))
|
2021-08-27 20:35:35 +08:00
|
|
|
t.Assert(len(m), 1)
|
|
|
|
t.AssertNE(m["reset_password_token_at"], nil)
|
|
|
|
t.Assert(m["reset_password_token_at"], new(mysql.NullTime))
|
|
|
|
})
|
|
|
|
}
|