2020-04-30 09:33:47 +00:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"background/config"
|
|
|
|
"background/db"
|
|
|
|
"background/logs"
|
|
|
|
"background/model"
|
|
|
|
"log"
|
|
|
|
"testing"
|
|
|
|
)
|
2020-11-10 16:05:17 +00:00
|
|
|
|
2020-04-30 09:33:47 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2020-11-10 16:05:17 +00:00
|
|
|
func InitElasticSearch() {
|
|
|
|
e := db.GetElastic().CreateIndex("hardware", model.HardwareTypeMapping())
|
|
|
|
if nil != e {
|
2020-04-30 09:33:47 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
func InitLogs() {
|
|
|
|
logs.Init(config.GetLogConfig().Dir, config.GetLogConfig().File, config.GetLogConfig().Level, config.GetLogConfig().SaveFile)
|
|
|
|
}
|
2020-11-10 16:05:17 +00:00
|
|
|
func TestPortDocToElastic(t *testing.T) {
|
2020-04-30 09:33:47 +00:00
|
|
|
InitConfig()
|
|
|
|
InitLogs()
|
|
|
|
InitRedisConfig()
|
|
|
|
InitMysql()
|
|
|
|
InitElasticSearch()
|
|
|
|
db.InitELK()
|
|
|
|
e := model.PortDocumentToElasticsearch("doc")
|
2020-11-10 16:05:17 +00:00
|
|
|
if nil != e {
|
2020-04-30 09:33:47 +00:00
|
|
|
t.Error(e)
|
|
|
|
}
|
2020-11-10 16:05:17 +00:00
|
|
|
}
|