github.com/gogf/gf@v1.16.9/database/gdb/gdb_z_mysql_basic_test.go (about)

     1  // Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/gogf/gf.
     6  
     7  package gdb_test
     8  
     9  import (
    10  	"github.com/go-sql-driver/mysql"
    11  	"github.com/gogf/gf/database/gdb"
    12  	"github.com/gogf/gf/test/gtest"
    13  	"testing"
    14  )
    15  
    16  func Test_Instance(t *testing.T) {
    17  	gtest.C(t, func(t *gtest.T) {
    18  		_, err := gdb.Instance("none")
    19  		t.AssertNE(err, nil)
    20  
    21  		db, err := gdb.Instance()
    22  		t.AssertNil(err)
    23  
    24  		err1 := db.PingMaster()
    25  		err2 := db.PingSlave()
    26  		t.Assert(err1, nil)
    27  		t.Assert(err2, nil)
    28  	})
    29  }
    30  
    31  // Fix issue: https://github.com/gogf/gf/issues/819
    32  func Test_Func_ConvertDataForTableRecord(t *testing.T) {
    33  	type Test struct {
    34  		ResetPasswordTokenAt mysql.NullTime `orm:"reset_password_token_at"`
    35  	}
    36  	gtest.C(t, func(t *gtest.T) {
    37  		m := gdb.ConvertDataForTableRecord(new(Test))
    38  		t.Assert(len(m), 1)
    39  		t.AssertNE(m["reset_password_token_at"], nil)
    40  		t.Assert(m["reset_password_token_at"], new(mysql.NullTime))
    41  	})
    42  }