ai_scheduler/internal/data/constants/user_test.go

92 lines
3.4 KiB
Go

package constants
import (
"ai_scheduler/internal/biz"
"ai_scheduler/internal/biz/do"
"ai_scheduler/internal/biz/llm_service"
"ai_scheduler/internal/data/impl"
"ai_scheduler/internal/entitys"
"ai_scheduler/internal/gateway"
"ai_scheduler/internal/pkg/dingtalk"
"ai_scheduler/internal/pkg/utils_ollama"
"ai_scheduler/internal/pkg/utils_vllm"
"ai_scheduler/internal/server"
"ai_scheduler/internal/services"
"ai_scheduler/internal/tools"
"ai_scheduler/internal/tools_bot"
"ai_scheduler/utils"
"os"
"testing"
)
const
func TestMain(m *testing.M) {
bootstrap := initialize.LoadConfigWithTest()
businessLogger := log2.NewBusinessLogger(bootstrap.Logs, id, Name, Version)
helper := pkg.NewLogHelper(businessLogger, bootstrap)
db, cleanup := utils.NewGormDb(configConfig)
sysImpl := impl.NewSysImpl(db)
taskImpl := impl.NewTaskImpl(db)
chatHisImpl := impl.NewChatHisImpl(db)
doDo := do.NewDo(sysImpl, taskImpl, chatHisImpl, configConfig)
client, cleanup2, err := utils_ollama.NewClient(configConfig)
if err != nil {
cleanup()
return nil, nil, err
}
utils_vllmClient, cleanup3, err := utils_vllm.NewClient(configConfig)
if err != nil {
cleanup2()
cleanup()
return nil, nil, err
}
ollamaService := llm_service.NewOllamaGenerate(client, utils_vllmClient, configConfig, chatHisImpl)
manager := tools.NewManager(configConfig, client)
sessionImpl := impl.NewSessionImpl(db)
botTool := tools_bot.NewBotTool(configConfig, client, sessionImpl)
handle := do.NewHandle(ollamaService, manager, configConfig, sessionImpl, botTool)
aiRouterBiz := biz.NewAiRouterBiz(doDo, handle)
chatHistoryBiz := biz.NewChatHistoryBiz(chatHisImpl, taskImpl)
gatewayGateway := gateway.NewGateway()
chatService := services.NewChatService(aiRouterBiz, chatHistoryBiz, gatewayGateway, configConfig)
sessionBiz := biz.NewSessionBiz(configConfig, sessionImpl, sysImpl, chatHisImpl)
sessionService := services.NewSessionService(sessionBiz, chatHistoryBiz)
taskBiz := biz.NewTaskBiz(configConfig, taskImpl)
taskService := services.NewTaskService(sessionBiz, taskBiz)
oldClient := dingtalk.NewOldClient(configConfig)
contactClient, err := dingtalk.NewContactClient(configConfig)
if err != nil {
cleanup3()
cleanup2()
cleanup()
return nil, nil, err
}
notableClient, err := dingtalk.NewNotableClient(configConfig)
if err != nil {
cleanup3()
cleanup2()
cleanup()
return nil, nil, err
}
callbackService := services.NewCallbackService(configConfig, gatewayGateway, oldClient, contactClient, notableClient, botTool)
historyService := services.NewHistoryService(chatHistoryBiz)
app := server.NewHTTPServer(chatService, sessionService, taskService, gatewayGateway, callbackService, historyService)
botConfigImpl := impl.NewBotConfigImpl(db)
dingTalkBotBiz := biz.NewDingTalkBotBiz(doDo, handle, botConfigImpl)
dingBotService := services.NewDingBotService(configConfig, dingTalkBotBiz)
v := server.ProvideAllDingBotServices(dingBotService)
dingTalkBotServer := server.NewDingTalkBotServer(v)
servers := server.NewServers(configConfig, app, dingTalkBotServer)
code := m.Run()
os.Exit(code)
}
func Test_GetUserInfo(t *testing.T) {
var c entitys.TaskConfig
config := `{"param": {"type": "object", "required": ["number"], "properties": {"number": {"type": "string", "description": "订单编号/流水号"}}}, "request": {"url": "http://www.baidu.com/${number}", "headers": {"Authorization": "${authorization}"}, "method": "GET"}}`
err := json.Unmarshal([]byte(config), &c)
t.Log(err)
}