geoGo/deepseek_test.go

79 lines
2.0 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package collect
import (
"context"
"geo/internal/collect"
"geo/internal/config"
"testing"
"github.com/gofiber/fiber/v2/log"
)
var (
deepseekCfg, _ = config.LoadConfig()
deepseekManager = collect.NewCollectManager(context.Background(), deepseekCfg, log.DefaultLogger())
)
// TestDeepseekCollector_WaitLogin 测试DeepSeek登录功能
func TestDeepseekCollector_WaitLogin(t *testing.T) {
if testing.Short() {
t.Skip("跳过需要浏览器交互的测试")
}
params := &collect.CollectParams{
Headless: false, // 显示浏览器窗口以便扫码登录
RequestID: "test_deepseek_login_001",
Platform: "deepseek",
}
t.Log("开始测试DeepSeek登录...")
t.Log("请在打开的浏览器窗口中完成DeepSeek账号登录扫码或输入账号密码")
success, msg := deepseekManager.WaitLogin("deepseek", params)
if !success {
t.Errorf("DeepSeek登录失败: %s", msg)
return
}
t.Logf("DeepSeek登录成功: %s", msg)
t.Log("Cookie已保存后续测试可以使用已登录状态")
}
// TestDeepseekCollector_AskQuestion 测试DeepSeek提问功能
// 注意:此测试需要有效的登录状态
func TestDeepseekCollector_AskQuestion(t *testing.T) {
if testing.Short() {
t.Skip("跳过需要浏览器交互的测试")
}
// 设置收集参数
params := &collect.CollectParams{
Headless: false, // 显示浏览器以便调试
RequestID: "test_deepseek_001",
Platform: "deepseek",
KeyWords: []string{"AI", "人工智能"}, // 测试关键词高亮
}
// 定义提问内容
question := "什么是人工智能?"
t.Logf("向DeepSeek提问: %s", question)
// 调用管理器提问并获取答案
result, err := deepseekManager.AskQuestion("deepseek", params, question)
if err != nil {
t.Errorf("提问失败: %v", err)
return
}
t.Logf("获取到答案:\n%s", result.Answer)
t.Logf("分享链接: %s", result.ShareLink)
t.Logf("是否包含关键词: %v", result.IsExposure)
// 验证答案非空
if len(result.Answer) == 0 {
t.Error("答案为空")
}
}