test: add test cases for anthropic protocol with API key
- Verify anthropic protocol returns *ClaudeProvider (not *HTTPProvider) - Test custom api_base for Anthropic-compatible endpoints - Test missing API key error message Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
9907fae594
commit
3e1e2b77de
1 changed files with 42 additions and 0 deletions
|
|
@ -152,6 +152,48 @@ func TestCreateProviderFromConfig_Anthropic(t *testing.T) {
|
||||||
if modelID != "claude-sonnet-4.6" {
|
if modelID != "claude-sonnet-4.6" {
|
||||||
t.Errorf("modelID = %q, want %q", modelID, "claude-sonnet-4.6")
|
t.Errorf("modelID = %q, want %q", modelID, "claude-sonnet-4.6")
|
||||||
}
|
}
|
||||||
|
// Should use ClaudeProvider (Anthropic SDK), not HTTPProvider
|
||||||
|
if _, ok := provider.(*ClaudeProvider); !ok {
|
||||||
|
t.Errorf("expected *ClaudeProvider, got %T", provider)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCreateProviderFromConfig_AnthropicWithCustomAPIBase(t *testing.T) {
|
||||||
|
cfg := &config.ModelConfig{
|
||||||
|
ModelName: "test-anthropic-custom",
|
||||||
|
Model: "anthropic/glm-4.7",
|
||||||
|
APIKey: "test-key",
|
||||||
|
APIBase: "https://api.z.ai/api/anthropic/v1",
|
||||||
|
}
|
||||||
|
|
||||||
|
provider, modelID, err := CreateProviderFromConfig(cfg)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("CreateProviderFromConfig() error = %v", err)
|
||||||
|
}
|
||||||
|
if provider == nil {
|
||||||
|
t.Fatal("CreateProviderFromConfig() returned nil provider")
|
||||||
|
}
|
||||||
|
if modelID != "glm-4.7" {
|
||||||
|
t.Errorf("modelID = %q, want %q", modelID, "glm-4.7")
|
||||||
|
}
|
||||||
|
if _, ok := provider.(*ClaudeProvider); !ok {
|
||||||
|
t.Errorf("expected *ClaudeProvider, got %T", provider)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCreateProviderFromConfig_AnthropicMissingAPIKey(t *testing.T) {
|
||||||
|
cfg := &config.ModelConfig{
|
||||||
|
ModelName: "test-anthropic-no-key",
|
||||||
|
Model: "anthropic/claude-sonnet-4.6",
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _, err := CreateProviderFromConfig(cfg)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("CreateProviderFromConfig() expected error for missing API key")
|
||||||
|
}
|
||||||
|
if !strings.Contains(err.Error(), "api_key is required") {
|
||||||
|
t.Errorf("error = %q, want message containing %q", err.Error(), "api_key is required")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCreateProviderFromConfig_Antigravity(t *testing.T) {
|
func TestCreateProviderFromConfig_Antigravity(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue