Files
InsightReply/server/internal/service/ai_service_test.go
zs 8cf6cb944b
Some checks failed
Extension Build & Release / build (push) Failing after 1m5s
Backend Deploy (Go + Docker) / deploy (push) Failing after 1m40s
Web Console Deploy (Vue 3 + Vite) / deploy (push) Has been cancelled
feat: 部署初版测试
2026-03-02 21:25:21 +08:00

42 lines
1.3 KiB
Go

package service
import (
"os"
"testing"
)
// TestAIService_Initialization verifies that the AIService parses environment variables
// correctly and initializes the required fallback strategies and default settings.
func TestAIService_Initialization(t *testing.T) {
// Temporarily set testing ENVs to avoid depending on local .env
os.Setenv("LLM_PROVIDER", "anthropic")
os.Setenv("LLM_MODEL", "claude-3-5-haiku-latest")
os.Setenv("OPENAI_API_KEY", "test-key-openai")
defer os.Clearenv() // Clean up after test
svc := NewAIService()
if svc == nil {
t.Fatal("Expected AIService to be initialized, got nil")
}
if svc.defaultProvider != "anthropic" {
t.Errorf("Expected default provider 'anthropic', got '%s'", svc.defaultProvider)
}
if svc.defaultModel != "claude-3-5-haiku-latest" {
t.Errorf("Expected default model 'claude-3-5-haiku-latest', got '%s'", svc.defaultModel)
}
// Verify that OpenAI provider was initialized because OPENAI_API_KEY was present
_, hasOpenAI := svc.providers["openai"]
if !hasOpenAI {
t.Error("Expected OpenAI provider to be initialized, but it was not found")
}
// Verify that circuit breakers were initialized
_, hasBreaker := svc.breakers["openai"]
if !hasBreaker {
t.Error("Expected circuit breaker for setup provider, but it was not found")
}
}