package tests

import (
	"ability/protocol"
	"github.com/astaxie/beego"
	_ "github.com/go-sql-driver/mysql"
	"gitlab.fjmaimaimai.com/mmm-go/gocomm/config"
	"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
	"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/orm"
	"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/redis"
	"os"
	"path/filepath"
	"runtime"
	"sync"
)

var one sync.Once

func Init() {
	one.Do(func() {
		_, file, _, _ := runtime.Caller(0)
		apppath, _ := filepath.Abs(filepath.Dir(filepath.Join(file, ".."+string(filepath.Separator))))
		beego.TestBeegoInit(apppath)

		path, _ := os.Getwd()
		filename := "app.conf"
		beego.LoadAppConfig("ini", filepath.Join(path, "conf", filename))
		log.InitLog(config.Logger{
			Filename: "app.log",
			Level:    "3", //7
		})
		err := redis.InitWithDb(100, beego.AppConfig.String("redis_add_port"), beego.AppConfig.String("redis_auth"), "0")
		if err != nil {
			log.Fatal(err)
			panic(err)
		}
		orm.NewBeeormEngine(config.Mysql{
			DataSource: beego.AppConfig.String("data_source"),
			MaxIdle:    100,
			MaxOpen:    100,
		})
		protocol.InitMessageCode()
	})
}