test(antigravity): add missing unit tests for upstream and custom model_mapping
- Add GetAccessToken upstream branch tests (success/failure/empty/nil) - Add mapAntigravityModel wildcard-target-equals-request edge case tests - Add upstream account smart retry test case - Add GeminiMessagesCompatService custom model_mapping and empty model tests
This commit is contained in:
@@ -265,3 +265,58 @@ func TestAntigravityGatewayService_IsModelSupported(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestMapAntigravityModel_WildcardTargetEqualsRequest 测试通配符映射目标恰好等于请求模型名的 edge case
|
||||
// 例如 {"claude-*": "claude-sonnet-4-5"},请求 "claude-sonnet-4-5" 时应该通过
|
||||
func TestMapAntigravityModel_WildcardTargetEqualsRequest(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
modelMapping map[string]any
|
||||
requestedModel string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "wildcard target equals request model",
|
||||
modelMapping: map[string]any{"claude-*": "claude-sonnet-4-5"},
|
||||
requestedModel: "claude-sonnet-4-5",
|
||||
expected: "claude-sonnet-4-5",
|
||||
},
|
||||
{
|
||||
name: "wildcard target differs from request model",
|
||||
modelMapping: map[string]any{"claude-*": "claude-sonnet-4-5"},
|
||||
requestedModel: "claude-opus-4-6",
|
||||
expected: "claude-sonnet-4-5",
|
||||
},
|
||||
{
|
||||
name: "wildcard no match",
|
||||
modelMapping: map[string]any{"claude-*": "claude-sonnet-4-5"},
|
||||
requestedModel: "gpt-4o",
|
||||
expected: "",
|
||||
},
|
||||
{
|
||||
name: "explicit passthrough same name",
|
||||
modelMapping: map[string]any{"claude-sonnet-4-5": "claude-sonnet-4-5"},
|
||||
requestedModel: "claude-sonnet-4-5",
|
||||
expected: "claude-sonnet-4-5",
|
||||
},
|
||||
{
|
||||
name: "multiple wildcards target equals one request",
|
||||
modelMapping: map[string]any{"claude-*": "claude-sonnet-4-5", "gemini-*": "gemini-2.5-flash"},
|
||||
requestedModel: "gemini-2.5-flash",
|
||||
expected: "gemini-2.5-flash",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
account := &Account{
|
||||
Platform: PlatformAntigravity,
|
||||
Credentials: map[string]any{
|
||||
"model_mapping": tt.modelMapping,
|
||||
},
|
||||
}
|
||||
got := mapAntigravityModel(account, tt.requestedModel)
|
||||
require.Equal(t, tt.expected, got, "mapAntigravityModel(%q) = %q, want %q", tt.requestedModel, got, tt.expected)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user