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

@@ -13,6 +13,7 @@ import (
"github.com/hhs/camtalk/internal/ai/llm"
"github.com/hhs/camtalk/internal/ai/stt"
"github.com/hhs/camtalk/internal/ai/tts"
"github.com/hhs/camtalk/internal/config"
"github.com/hhs/camtalk/internal/logger"
"github.com/hhs/camtalk/internal/models"
)
@@ -254,7 +255,12 @@ func TestProcessQuery_Success(t *testing.T) {
mockSender.On("SendTTSAudio", mock.Anything).Return(nil)
// 创建 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()
@@ -305,7 +311,12 @@ func TestProcessQuery_STTError(t *testing.T) {
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()
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)
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()
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).
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()
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)
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())
@@ -545,7 +571,12 @@ func TestProcessQuery_DisabledTTS(t *testing.T) {
mockSender.On("SendLLMChunk", 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()
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)
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()
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)
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()
err := pipeline.ProcessQuery(ctx, "session-123", req, nil, mockSender)