TestProviderFactory 测试工厂模式
(t *testing.T)
| 316 | |
| 317 | // TestProviderFactory 测试工厂模式 |
| 318 | func TestProviderFactory(t *testing.T) { |
| 319 | factory := NewMultiProviderFactory() |
| 320 | |
| 321 | testCases := []struct { |
| 322 | provider string |
| 323 | model string |
| 324 | apiKey string |
| 325 | baseURL string |
| 326 | }{ |
| 327 | {"openai", "gpt-4o", "test-key", ""}, |
| 328 | {"groq", "llama-3.3-70b-versatile", "test-key", ""}, |
| 329 | {"ollama", "llama3.2", "", ""}, |
| 330 | {"openrouter", "openai/gpt-4o", "test-key", ""}, |
| 331 | {"mistral", "mistral-large-latest", "test-key", ""}, |
| 332 | {"doubao", "ep-xxxxx", "test-key", ""}, |
| 333 | {"moonshot", "moonshot-v1-128k", "test-key", ""}, |
| 334 | {"gemini", "gemini-2.0-flash-exp", "test-key", ""}, |
| 335 | {"custom", "gpt-4o", "test-key", "https://api.example.com/v1"}, |
| 336 | } |
| 337 | |
| 338 | for _, tc := range testCases { |
| 339 | t.Run(tc.provider, func(t *testing.T) { |
| 340 | config := &types.ModelConfig{ |
| 341 | Provider: tc.provider, |
| 342 | Model: tc.model, |
| 343 | APIKey: tc.apiKey, |
| 344 | BaseURL: tc.baseURL, |
| 345 | } |
| 346 | |
| 347 | provider, err := factory.Create(config) |
| 348 | if err != nil { |
| 349 | t.Fatalf("Failed to create provider %s: %v", tc.provider, err) |
| 350 | } |
| 351 | |
| 352 | if provider == nil { |
| 353 | t.Fatalf("Provider %s is nil", tc.provider) |
| 354 | } |
| 355 | |
| 356 | // 验证基本功能 |
| 357 | caps := provider.Capabilities() |
| 358 | if !caps.SupportStreaming { |
| 359 | t.Errorf("Provider %s should support streaming", tc.provider) |
| 360 | } |
| 361 | }) |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | // TestMessageConversion 测试消息转换 |
| 366 | func TestMessageConversion(t *testing.T) { |
nothing calls this directly
no test coverage detected