test: 更新测试文件适配构造函数签名变更

This commit is contained in:
hhs
2026-06-14 11:55:29 +08:00
parent 544716fe27
commit 96cf009228
7 changed files with 86 additions and 39 deletions

View File

@@ -53,7 +53,7 @@ func TestOpenAIService_ChatStream_Success(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewOpenAIService("test-key", "gpt-4o", srv.URL, 10, zap.NewNop().Sugar()) svc := NewOpenAIService("test-key", "gpt-4o", srv.URL, 10, 60, zap.NewNop().Sugar())
ch, err := svc.ChatStream(context.Background(), Request{ ch, err := svc.ChatStream(context.Background(), Request{
Text: "这是什么?", Text: "这是什么?",
@@ -99,7 +99,7 @@ func TestOpenAIService_ChatStream_WithImage(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewOpenAIService("test-key", "gpt-4o", srv.URL, 10, zap.NewNop().Sugar()) svc := NewOpenAIService("test-key", "gpt-4o", srv.URL, 10, 60, zap.NewNop().Sugar())
ch, err := svc.ChatStream(context.Background(), Request{ ch, err := svc.ChatStream(context.Background(), Request{
Image: []byte("fake-jpeg-data"), Image: []byte("fake-jpeg-data"),
@@ -123,7 +123,7 @@ func TestOpenAIService_ChatStream_WithHistory(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewOpenAIService("test-key", "gpt-4o", srv.URL, 10, zap.NewNop().Sugar()) svc := NewOpenAIService("test-key", "gpt-4o", srv.URL, 10, 60, zap.NewNop().Sugar())
ch, err := svc.ChatStream(context.Background(), Request{ ch, err := svc.ChatStream(context.Background(), Request{
Text: "继续", Text: "继续",
@@ -149,7 +149,7 @@ func TestOpenAIService_ChatStream_APIError(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewOpenAIService("bad-key", "gpt-4o", srv.URL, 10, zap.NewNop().Sugar()) svc := NewOpenAIService("bad-key", "gpt-4o", srv.URL, 10, 60, zap.NewNop().Sugar())
_, err := svc.ChatStream(context.Background(), Request{ _, err := svc.ChatStream(context.Background(), Request{
Text: "test", Text: "test",
@@ -172,7 +172,7 @@ func TestOpenAIService_ChatStream_Timeout(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewOpenAIService("test-key", "gpt-4o", srv.URL, 1, zap.NewNop().Sugar()) // 1s timeout svc := NewOpenAIService("test-key", "gpt-4o", srv.URL, 1, 60, zap.NewNop().Sugar()) // 1s timeout
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel() defer cancel()
@@ -204,7 +204,7 @@ func TestOpenAIService_ChatStream_UsageInResponse(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewOpenAIService("test-key", "gpt-4o", srv.URL, 10, zap.NewNop().Sugar()) svc := NewOpenAIService("test-key", "gpt-4o", srv.URL, 10, 60, zap.NewNop().Sugar())
ch, err := svc.ChatStream(context.Background(), Request{Text: "test"}) ch, err := svc.ChatStream(context.Background(), Request{Text: "test"})
if err != nil { if err != nil {

View File

@@ -74,7 +74,7 @@ func TestDeepgramService_Recognize_Success(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewDeepgramService("test-key", "", wsToWss(srv.URL)+"/v1/listen", zap.NewNop().Sugar()) svc := NewDeepgramService("test-key", "", wsToWss(srv.URL)+"/v1/listen", 0, zap.NewNop().Sugar())
text, err := svc.Recognize(context.Background(), []byte("fake-pcm-audio"), Options{ text, err := svc.Recognize(context.Background(), []byte("fake-pcm-audio"), Options{
Encoding: "pcm_s16le", Encoding: "pcm_s16le",
@@ -90,7 +90,7 @@ func TestDeepgramService_Recognize_Success(t *testing.T) {
} }
func TestDeepgramService_Recognize_EmptyAudio(t *testing.T) { func TestDeepgramService_Recognize_EmptyAudio(t *testing.T) {
svc := NewDeepgramService("test-key", "", "ws://localhost", zap.NewNop().Sugar()) svc := NewDeepgramService("test-key", "", "ws://localhost", 0, zap.NewNop().Sugar())
_, err := svc.Recognize(context.Background(), nil, Options{}) _, err := svc.Recognize(context.Background(), nil, Options{})
if err == nil { if err == nil {
t.Fatal("Recognize() with empty audio should return error") t.Fatal("Recognize() with empty audio should return error")
@@ -98,7 +98,7 @@ func TestDeepgramService_Recognize_EmptyAudio(t *testing.T) {
} }
func TestDeepgramService_Recognize_ConnectError(t *testing.T) { func TestDeepgramService_Recognize_ConnectError(t *testing.T) {
svc := NewDeepgramService("test-key", "", "ws://localhost:1", zap.NewNop().Sugar()) svc := NewDeepgramService("test-key", "", "ws://localhost:1", 0, zap.NewNop().Sugar())
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel() defer cancel()
@@ -117,7 +117,7 @@ func TestDeepgramService_Recognize_Timeout(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewDeepgramService("test-key", "", wsToWss(srv.URL)+"/v1/listen", zap.NewNop().Sugar()) svc := NewDeepgramService("test-key", "", wsToWss(srv.URL)+"/v1/listen", 0, zap.NewNop().Sugar())
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel() defer cancel()
@@ -147,7 +147,7 @@ func TestDeepgramService_Recognize_MultipleFinals(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewDeepgramService("test-key", "", wsToWss(srv.URL)+"/v1/listen", zap.NewNop().Sugar()) svc := NewDeepgramService("test-key", "", wsToWss(srv.URL)+"/v1/listen", 0, zap.NewNop().Sugar())
text, err := svc.Recognize(context.Background(), []byte("audio"), Options{}) text, err := svc.Recognize(context.Background(), []byte("audio"), Options{})
if err != nil { if err != nil {
@@ -159,7 +159,7 @@ func TestDeepgramService_Recognize_MultipleFinals(t *testing.T) {
} }
func TestDeepgramService_buildURL(t *testing.T) { func TestDeepgramService_buildURL(t *testing.T) {
svc := NewDeepgramService("key", "", "wss://api.deepgram.com/v1/listen", zap.NewNop().Sugar()) svc := NewDeepgramService("key", "", "wss://api.deepgram.com/v1/listen", 0, zap.NewNop().Sugar())
tests := []struct { tests := []struct {
name string name string

View File

@@ -14,7 +14,7 @@ import (
func newTestMiMoService(handler http.HandlerFunc) (*MiMoService, *httptest.Server) { func newTestMiMoService(handler http.HandlerFunc) (*MiMoService, *httptest.Server) {
srv := httptest.NewServer(handler) srv := httptest.NewServer(handler)
s := NewMiMoService("test-key", "mimo-v2.5-asr", srv.URL, zap.NewNop().Sugar()) s := NewMiMoService("test-key", "mimo-v2.5-asr", srv.URL, 0, zap.NewNop().Sugar())
return s, srv return s, srv
} }

View File

@@ -93,7 +93,7 @@ func TestMiMoService_SynthesizeStream_Success(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewMiMoService("test-key", "", "冰糖", srv.URL, 5, zap.NewNop().Sugar()) svc := NewMiMoService("test-key", "mimo-v2.5-tts", "冰糖", srv.URL, 5, 30, zap.NewNop().Sugar())
textStream := sendSentences("你好", "世界", "") textStream := sendSentences("你好", "世界", "")
@@ -145,7 +145,7 @@ func TestMiMoService_SynthesizeStream_APIError(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewMiMoService("test-key", "", "冰糖", srv.URL, 5, zap.NewNop().Sugar()) svc := NewMiMoService("test-key", "mimo-v2.5-tts", "冰糖", srv.URL, 5, 30, zap.NewNop().Sugar())
textStream := sendSentences("你好") textStream := sendSentences("你好")
@@ -178,7 +178,7 @@ func TestMiMoService_SynthesizeStream_Timeout(t *testing.T) {
defer srv.Close() defer srv.Close()
// 1 秒超时 // 1 秒超时
svc := NewMiMoService("test-key", "", "冰糖", srv.URL, 1, zap.NewNop().Sugar()) svc := NewMiMoService("test-key", "mimo-v2.5-tts", "冰糖", srv.URL, 1, 30, zap.NewNop().Sugar())
textStream := sendSentences("很长的句子") textStream := sendSentences("很长的句子")
@@ -214,7 +214,7 @@ func TestMiMoService_SynthesizeStream_EmptyText(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewMiMoService("test-key", "", "冰糖", srv.URL, 5, zap.NewNop().Sugar()) svc := NewMiMoService("test-key", "mimo-v2.5-tts", "冰糖", srv.URL, 5, 30, zap.NewNop().Sugar())
// 空句子应该被跳过 // 空句子应该被跳过
textStream := sendSentences("", "你好", "") textStream := sendSentences("", "你好", "")
@@ -248,7 +248,7 @@ func TestMiMoService_SynthesizeStream_ContextCancelled(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewMiMoService("test-key", "", "冰糖", srv.URL, 5, zap.NewNop().Sugar()) svc := NewMiMoService("test-key", "mimo-v2.5-tts", "冰糖", srv.URL, 5, 30, zap.NewNop().Sugar())
textStream := make(chan string, 3) textStream := make(chan string, 3)
textStream <- "第一句" textStream <- "第一句"
@@ -290,7 +290,7 @@ func TestMiMoService_SynthesizeStream_PartialFailure(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewMiMoService("test-key", "", "冰糖", srv.URL, 5, zap.NewNop().Sugar()) svc := NewMiMoService("test-key", "mimo-v2.5-tts", "冰糖", srv.URL, 5, 30, zap.NewNop().Sugar())
textStream := sendSentences("第一句", "第二句", "第三句") textStream := sendSentences("第一句", "第二句", "第三句")
@@ -329,7 +329,7 @@ func TestMiMoService_SynthesizeStream_CustomVoice(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewMiMoService("test-key", "", "冰糖", srv.URL, 5, zap.NewNop().Sugar()) svc := NewMiMoService("test-key", "mimo-v2.5-tts", "冰糖", srv.URL, 5, 30, zap.NewNop().Sugar())
textStream := sendSentences("你好") textStream := sendSentences("你好")
@@ -360,7 +360,7 @@ func TestMiMoService_SynthesizeStream_DefaultVoice(t *testing.T) {
defer srv.Close() defer srv.Close()
// 不指定 voice // 不指定 voice
svc := NewMiMoService("test-key", "", "", srv.URL, 5, zap.NewNop().Sugar()) svc := NewMiMoService("test-key", "mimo-v2.5-tts", "冰糖", srv.URL, 5, 30, zap.NewNop().Sugar())
textStream := sendSentences("你好") textStream := sendSentences("你好")
@@ -381,7 +381,7 @@ func TestMiMoService_SynthesizeStream_EmptyAudioData(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewMiMoService("test-key", "", "冰糖", srv.URL, 5, zap.NewNop().Sugar()) svc := NewMiMoService("test-key", "mimo-v2.5-tts", "冰糖", srv.URL, 5, 30, zap.NewNop().Sugar())
textStream := sendSentences("你好") textStream := sendSentences("你好")

View File

@@ -58,7 +58,7 @@ func TestOpenAIService_SynthesizeStream_Success(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewOpenAIService("test-key", "", "alloy", srv.URL, 1.0, 5, zap.NewNop().Sugar()) svc := NewOpenAIService("test-key", "tts-1", "alloy", srv.URL, 1.0, 5, 30, zap.NewNop().Sugar())
textStream := sendSentences("你好", "世界", "") textStream := sendSentences("你好", "世界", "")
@@ -110,7 +110,7 @@ func TestOpenAIService_SynthesizeStream_APIError(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewOpenAIService("test-key", "", "alloy", srv.URL, 1.0, 5, zap.NewNop().Sugar()) svc := NewOpenAIService("test-key", "tts-1", "alloy", srv.URL, 1.0, 5, 30, zap.NewNop().Sugar())
textStream := sendSentences("你好") textStream := sendSentences("你好")
@@ -142,7 +142,7 @@ func TestOpenAIService_SynthesizeStream_Timeout(t *testing.T) {
defer srv.Close() defer srv.Close()
// 1 秒超时 // 1 秒超时
svc := NewOpenAIService("test-key", "", "alloy", srv.URL, 1.0, 1, zap.NewNop().Sugar()) svc := NewOpenAIService("test-key", "tts-1", "alloy", srv.URL, 1.0, 1, 30, zap.NewNop().Sugar())
textStream := sendSentences("很长的句子") textStream := sendSentences("很长的句子")
@@ -177,7 +177,7 @@ func TestOpenAIService_SynthesizeStream_EmptyText(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewOpenAIService("test-key", "", "alloy", srv.URL, 1.0, 5, zap.NewNop().Sugar()) svc := NewOpenAIService("test-key", "tts-1", "alloy", srv.URL, 1.0, 5, 30, zap.NewNop().Sugar())
// 空句子应该被跳过 // 空句子应该被跳过
textStream := sendSentences("", "你好", "") textStream := sendSentences("", "你好", "")
@@ -210,7 +210,7 @@ func TestOpenAIService_SynthesizeStream_ContextCancelled(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewOpenAIService("test-key", "", "alloy", srv.URL, 1.0, 5, zap.NewNop().Sugar()) svc := NewOpenAIService("test-key", "tts-1", "alloy", srv.URL, 1.0, 5, 30, zap.NewNop().Sugar())
// 发送多个句子,但在第一个后取消 // 发送多个句子,但在第一个后取消
textStream := make(chan string, 3) textStream := make(chan string, 3)
@@ -252,7 +252,7 @@ func TestOpenAIService_SynthesizeStream_PartialFailure(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewOpenAIService("test-key", "", "alloy", srv.URL, 1.0, 5, zap.NewNop().Sugar()) svc := NewOpenAIService("test-key", "tts-1", "alloy", srv.URL, 1.0, 5, 30, zap.NewNop().Sugar())
textStream := sendSentences("第一句", "第二句", "第三句") textStream := sendSentences("第一句", "第二句", "第三句")
@@ -286,7 +286,7 @@ func TestOpenAIService_SynthesizeStream_CustomVoice(t *testing.T) {
}) })
defer srv.Close() defer srv.Close()
svc := NewOpenAIService("test-key", "", "alloy", srv.URL, 1.0, 5, zap.NewNop().Sugar()) svc := NewOpenAIService("test-key", "tts-1", "alloy", srv.URL, 1.0, 5, 30, zap.NewNop().Sugar())
textStream := sendSentences("你好") textStream := sendSentences("你好")

View File

@@ -13,6 +13,7 @@ import (
"github.com/hhs/camtalk/internal/ai/llm" "github.com/hhs/camtalk/internal/ai/llm"
"github.com/hhs/camtalk/internal/ai/stt" "github.com/hhs/camtalk/internal/ai/stt"
"github.com/hhs/camtalk/internal/ai/tts" "github.com/hhs/camtalk/internal/ai/tts"
"github.com/hhs/camtalk/internal/config"
"github.com/hhs/camtalk/internal/logger" "github.com/hhs/camtalk/internal/logger"
"github.com/hhs/camtalk/internal/models" "github.com/hhs/camtalk/internal/models"
) )
@@ -254,7 +255,12 @@ func TestProcessQuery_Success(t *testing.T) {
mockSender.On("SendTTSAudio", mock.Anything).Return(nil) mockSender.On("SendTTSAudio", mock.Anything).Return(nil)
// 创建 Pipeline // 创建 Pipeline
pipeline := New(mockSTT, mockLLM, mockTTS, mockSession, "gpt-4o", "alloy", 1.0) pipeline := New(mockSTT, mockLLM, mockTTS, mockSession, &config.Config{
AI: config.AIConfig{
LLM: config.LLMConfig{Model: "gpt-4o"},
TTS: config.TTSConfig{Voice: "alloy", Speed: 1.0, OutputFormat: "mp3", SampleRate: 24000},
},
})
// 执行 // 执行
ctx := context.Background() ctx := context.Background()
@@ -305,7 +311,12 @@ func TestProcessQuery_STTError(t *testing.T) {
mockSender.On("SendError", mock.Anything).Return(nil) mockSender.On("SendError", mock.Anything).Return(nil)
pipeline := New(mockSTT, mockLLM, mockTTS, mockSession, "gpt-4o", "alloy", 1.0) pipeline := New(mockSTT, mockLLM, mockTTS, mockSession, &config.Config{
AI: config.AIConfig{
LLM: config.LLMConfig{Model: "gpt-4o"},
TTS: config.TTSConfig{Voice: "alloy", Speed: 1.0, OutputFormat: "mp3", SampleRate: 24000},
},
})
ctx := context.Background() ctx := context.Background()
err := pipeline.ProcessQuery(ctx, "session-123", req, nil, mockSender) err := pipeline.ProcessQuery(ctx, "session-123", req, nil, mockSender)
@@ -357,7 +368,12 @@ func TestProcessQuery_LLMError(t *testing.T) {
mockSender.On("SendError", mock.Anything).Return(nil) mockSender.On("SendError", mock.Anything).Return(nil)
pipeline := New(mockSTT, mockLLM, mockTTS, mockSession, "gpt-4o", "alloy", 1.0) pipeline := New(mockSTT, mockLLM, mockTTS, mockSession, &config.Config{
AI: config.AIConfig{
LLM: config.LLMConfig{Model: "gpt-4o"},
TTS: config.TTSConfig{Voice: "alloy", Speed: 1.0, OutputFormat: "mp3", SampleRate: 24000},
},
})
ctx := context.Background() ctx := context.Background()
err := pipeline.ProcessQuery(ctx, "session-123", req, nil, mockSender) err := pipeline.ProcessQuery(ctx, "session-123", req, nil, mockSender)
@@ -415,7 +431,12 @@ func TestProcessQuery_TTSError(t *testing.T) {
mockTTS.On("SynthesizeStream", mock.Anything, mock.Anything, mock.Anything). mockTTS.On("SynthesizeStream", mock.Anything, mock.Anything, mock.Anything).
Return(nil, errors.New("TTS service unavailable")) Return(nil, errors.New("TTS service unavailable"))
pipeline := New(mockSTT, mockLLM, mockTTS, mockSession, "gpt-4o", "alloy", 1.0) pipeline := New(mockSTT, mockLLM, mockTTS, mockSession, &config.Config{
AI: config.AIConfig{
LLM: config.LLMConfig{Model: "gpt-4o"},
TTS: config.TTSConfig{Voice: "alloy", Speed: 1.0, OutputFormat: "mp3", SampleRate: 24000},
},
})
ctx := context.Background() ctx := context.Background()
err := pipeline.ProcessQuery(ctx, "session-123", req, nil, mockSender) err := pipeline.ProcessQuery(ctx, "session-123", req, nil, mockSender)
@@ -485,7 +506,12 @@ func TestProcessQuery_ContextCancelled(t *testing.T) {
}() }()
mockTTS.On("SynthesizeStream", mock.Anything, mock.Anything, mock.Anything).Return((<-chan tts.Chunk)(ttsCh), nil) mockTTS.On("SynthesizeStream", mock.Anything, mock.Anything, mock.Anything).Return((<-chan tts.Chunk)(ttsCh), nil)
pipeline := New(mockSTT, mockLLM, mockTTS, mockSession, "gpt-4o", "alloy", 1.0) pipeline := New(mockSTT, mockLLM, mockTTS, mockSession, &config.Config{
AI: config.AIConfig{
LLM: config.LLMConfig{Model: "gpt-4o"},
TTS: config.TTSConfig{Voice: "alloy", Speed: 1.0, OutputFormat: "mp3", SampleRate: 24000},
},
})
// 创建可取消的上下文 // 创建可取消的上下文
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
@@ -545,7 +571,12 @@ func TestProcessQuery_DisabledTTS(t *testing.T) {
mockSender.On("SendLLMChunk", mock.Anything).Return(nil) mockSender.On("SendLLMChunk", mock.Anything).Return(nil)
mockSender.On("SendLLMDone", mock.Anything).Return(nil) mockSender.On("SendLLMDone", mock.Anything).Return(nil)
pipeline := New(mockSTT, mockLLM, mockTTS, mockSession, "gpt-4o", "alloy", 1.0) pipeline := New(mockSTT, mockLLM, mockTTS, mockSession, &config.Config{
AI: config.AIConfig{
LLM: config.LLMConfig{Model: "gpt-4o"},
TTS: config.TTSConfig{Voice: "alloy", Speed: 1.0, OutputFormat: "mp3", SampleRate: 24000},
},
})
ctx := context.Background() ctx := context.Background()
err := pipeline.ProcessQuery(ctx, "session-123", req, nil, mockSender) err := pipeline.ProcessQuery(ctx, "session-123", req, nil, mockSender)
@@ -617,7 +648,12 @@ func TestProcessQuery_InvalidAudio(t *testing.T) {
mockSender.On("SendError", mock.Anything).Return(nil) mockSender.On("SendError", mock.Anything).Return(nil)
pipeline := New(mockSTT, mockLLM, mockTTS, mockSession, "gpt-4o", "alloy", 1.0) pipeline := New(mockSTT, mockLLM, mockTTS, mockSession, &config.Config{
AI: config.AIConfig{
LLM: config.LLMConfig{Model: "gpt-4o"},
TTS: config.TTSConfig{Voice: "alloy", Speed: 1.0, OutputFormat: "mp3", SampleRate: 24000},
},
})
ctx := context.Background() ctx := context.Background()
err := pipeline.ProcessQuery(ctx, "session-123", req, nil, mockSender) err := pipeline.ProcessQuery(ctx, "session-123", req, nil, mockSender)
@@ -650,7 +686,12 @@ func TestProcessQuery_SessionNotFound(t *testing.T) {
mockSender.On("SendError", mock.Anything).Return(nil) mockSender.On("SendError", mock.Anything).Return(nil)
pipeline := New(mockSTT, mockLLM, mockTTS, mockSession, "gpt-4o", "alloy", 1.0) pipeline := New(mockSTT, mockLLM, mockTTS, mockSession, &config.Config{
AI: config.AIConfig{
LLM: config.LLMConfig{Model: "gpt-4o"},
TTS: config.TTSConfig{Voice: "alloy", Speed: 1.0, OutputFormat: "mp3", SampleRate: 24000},
},
})
ctx := context.Background() ctx := context.Background()
err := pipeline.ProcessQuery(ctx, "session-123", req, nil, mockSender) err := pipeline.ProcessQuery(ctx, "session-123", req, nil, mockSender)

View File

@@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"context" "context"
"github.com/hhs/camtalk/internal/config"
"github.com/hhs/camtalk/internal/logger" "github.com/hhs/camtalk/internal/logger"
"github.com/hhs/camtalk/internal/models" "github.com/hhs/camtalk/internal/models"
"github.com/hhs/camtalk/internal/orchestrator" "github.com/hhs/camtalk/internal/orchestrator"
@@ -138,7 +139,12 @@ func setupTestServer(t *testing.T, orch orchestrator.Orchestrator) (*httptest.Se
t.Cleanup(func() { sessionMgr.Stop() }) t.Cleanup(func() { sessionMgr.Stop() })
r := gin.New() r := gin.New()
r.GET("/ws", ServeWS(sessionMgr, orch)) cfg := &config.Config{
App: config.AppConfig{Version: "test"},
Server: config.ServerConfig{HeartbeatInterval: 30, HeartbeatTimeout: 60},
Session: config.SessionConfig{MaxHistory: 20},
}
r.GET("/ws", ServeWS(sessionMgr, orch, cfg))
srv := httptest.NewServer(r) srv := httptest.NewServer(r)
@@ -181,7 +187,7 @@ func TestWS_Connected(t *testing.T) {
msg := readJSON(t, conn) msg := readJSON(t, conn)
assert.Equal(t, "connected", msg["type"]) assert.Equal(t, "connected", msg["type"])
assert.NotEmpty(t, msg["session_id"]) assert.NotEmpty(t, msg["session_id"])
assert.Equal(t, "0.1.0", msg["server_version"]) assert.Equal(t, "test", msg["server_version"])
} }
// TestWS_PingPong 验证 ping/pong 心跳。 // TestWS_PingPong 验证 ping/pong 心跳。