52 lines
936 B
Go
52 lines
936 B
Go
|
package test
|
||
|
|
||
|
import (
|
||
|
"background/config"
|
||
|
"background/db"
|
||
|
"background/logs"
|
||
|
"background/model"
|
||
|
"log"
|
||
|
"testing"
|
||
|
)
|
||
|
func InitConfig() {
|
||
|
e := config.Init("user.yaml")
|
||
|
if nil != e {
|
||
|
log.Println(e.Error())
|
||
|
}
|
||
|
}
|
||
|
func InitMysql() {
|
||
|
c := config.GetMysqlConfig()
|
||
|
if c == nil {
|
||
|
logs.Error("cannnot connect mysql server")
|
||
|
} else {
|
||
|
db.Init()
|
||
|
}
|
||
|
}
|
||
|
func InitRedisConfig() {
|
||
|
e := config.InitRedis()
|
||
|
if nil != e {
|
||
|
logs.Error(e.Error())
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
func InitElasticSearch(){
|
||
|
e := db.GetElastic().CreateIndex("hardware",model.HardwareTypeMapping())
|
||
|
if nil != e{
|
||
|
|
||
|
}
|
||
|
}
|
||
|
func InitLogs() {
|
||
|
logs.Init(config.GetLogConfig().Dir, config.GetLogConfig().File, config.GetLogConfig().Level, config.GetLogConfig().SaveFile)
|
||
|
}
|
||
|
func TestPortDocToElastic(t *testing.T) {
|
||
|
InitConfig()
|
||
|
InitLogs()
|
||
|
InitRedisConfig()
|
||
|
InitMysql()
|
||
|
InitElasticSearch()
|
||
|
db.InitELK()
|
||
|
e := model.PortDocumentToElasticsearch("doc")
|
||
|
if nil != e{
|
||
|
t.Error(e)
|
||
|
}
|
||
|
}
|