mirror of
https://github.com/zhufuyi/sponge.git
synced 2025-10-23 09:01:02 +08:00
39 lines
725 B
Go
39 lines
725 B
Go
package mysql
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
var dsn = "root:123456@(192.168.30.37:3306)/test?charset=utf8mb4&parseTime=True&loc=Local"
|
|
|
|
func TestInit(t *testing.T) {
|
|
db, err := Init(dsn)
|
|
if err != nil {
|
|
// 忽略无法连接真实mysql的测试错误
|
|
t.Logf(fmt.Sprintf("connect to mysql failed, err=%v, dsn=%s", err, dsn))
|
|
return
|
|
}
|
|
|
|
t.Logf("%+v", db.Name())
|
|
}
|
|
|
|
func Test_gormConfig(t *testing.T) {
|
|
o := defaultOptions()
|
|
o.apply(
|
|
WithLog(),
|
|
WithSlowThreshold(time.Millisecond*100),
|
|
WithEnableTrace(),
|
|
WithMaxIdleConns(5),
|
|
WithMaxOpenConns(50),
|
|
WithConnMaxLifetime(time.Minute*3),
|
|
WithEnableForeignKey(),
|
|
)
|
|
|
|
c := gormConfig(o)
|
|
assert.NotNil(t, c)
|
|
}
|