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:
97
backend/internal/service/antigravity_token_provider_test.go
Normal file
97
backend/internal/service/antigravity_token_provider_test.go
Normal file
@@ -0,0 +1,97 @@
|
||||
//go:build unit
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAntigravityTokenProvider_GetAccessToken_Upstream(t *testing.T) {
|
||||
provider := &AntigravityTokenProvider{}
|
||||
|
||||
t.Run("upstream account with valid api_key", func(t *testing.T) {
|
||||
account := &Account{
|
||||
Platform: PlatformAntigravity,
|
||||
Type: AccountTypeUpstream,
|
||||
Credentials: map[string]any{
|
||||
"api_key": "sk-test-key-12345",
|
||||
},
|
||||
}
|
||||
token, err := provider.GetAccessToken(context.Background(), account)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "sk-test-key-12345", token)
|
||||
})
|
||||
|
||||
t.Run("upstream account missing api_key", func(t *testing.T) {
|
||||
account := &Account{
|
||||
Platform: PlatformAntigravity,
|
||||
Type: AccountTypeUpstream,
|
||||
Credentials: map[string]any{},
|
||||
}
|
||||
token, err := provider.GetAccessToken(context.Background(), account)
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "upstream account missing api_key")
|
||||
require.Empty(t, token)
|
||||
})
|
||||
|
||||
t.Run("upstream account with empty api_key", func(t *testing.T) {
|
||||
account := &Account{
|
||||
Platform: PlatformAntigravity,
|
||||
Type: AccountTypeUpstream,
|
||||
Credentials: map[string]any{
|
||||
"api_key": "",
|
||||
},
|
||||
}
|
||||
token, err := provider.GetAccessToken(context.Background(), account)
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "upstream account missing api_key")
|
||||
require.Empty(t, token)
|
||||
})
|
||||
|
||||
t.Run("upstream account with nil credentials", func(t *testing.T) {
|
||||
account := &Account{
|
||||
Platform: PlatformAntigravity,
|
||||
Type: AccountTypeUpstream,
|
||||
}
|
||||
token, err := provider.GetAccessToken(context.Background(), account)
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "upstream account missing api_key")
|
||||
require.Empty(t, token)
|
||||
})
|
||||
}
|
||||
|
||||
func TestAntigravityTokenProvider_GetAccessToken_Guards(t *testing.T) {
|
||||
provider := &AntigravityTokenProvider{}
|
||||
|
||||
t.Run("nil account", func(t *testing.T) {
|
||||
token, err := provider.GetAccessToken(context.Background(), nil)
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "account is nil")
|
||||
require.Empty(t, token)
|
||||
})
|
||||
|
||||
t.Run("non-antigravity platform", func(t *testing.T) {
|
||||
account := &Account{
|
||||
Platform: PlatformAnthropic,
|
||||
Type: AccountTypeOAuth,
|
||||
}
|
||||
token, err := provider.GetAccessToken(context.Background(), account)
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "not an antigravity account")
|
||||
require.Empty(t, token)
|
||||
})
|
||||
|
||||
t.Run("unsupported account type", func(t *testing.T) {
|
||||
account := &Account{
|
||||
Platform: PlatformAntigravity,
|
||||
Type: AccountTypeAPIKey,
|
||||
}
|
||||
token, err := provider.GetAccessToken(context.Background(), account)
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), "not an antigravity oauth account")
|
||||
require.Empty(t, token)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user