package db

import (
	"LAPP_LF_MOM_BACKEND/conf"
	"fmt"
	"github.com/go-xorm/xorm"
	"log"
	"testing"
)

func TestDb(t *testing.T) {
	var (
		engine *xorm.Engine
		err    error
	)

	c := conf.DbConfig
	driveSource := fmt.Sprintf("server=%s;database=%s;user id=%s;password=%s;port=%d;encrypt=disable",
		c.Masterdbserver, c.Masterdbname, c.Masterdbuser, c.Masterdbuser, c.Masterdbport)
	fmt.Print(driveSource)
	if engine, err = xorm.NewEngine(c.Masterdbdrivername, driveSource); err != nil {
		t.Error(err)
		return
	}
	//开启sql，debug
	engine.ShowSQL(true)
	if err = engine.Ping(); err != nil {
		log.Println("数据库连接失败:", driveSource, err.Error())
		return
	} else {
		log.Println("数据库连接成功：", driveSource)
	}
}
