| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- //go:build unit
- package service
- import (
- "encoding/json"
- "testing"
- "github.com/stretchr/testify/require"
- )
- func TestGetPoolModeRetryCount(t *testing.T) {
- tests := []struct {
- name string
- account *Account
- expected int
- }{
- {
- name: "default_when_not_pool_mode",
- account: &Account{
- Type: AccountTypeAPIKey,
- Platform: PlatformOpenAI,
- Credentials: map[string]any{},
- },
- expected: defaultPoolModeRetryCount,
- },
- {
- name: "default_when_missing_retry_count",
- account: &Account{
- Type: AccountTypeAPIKey,
- Platform: PlatformOpenAI,
- Credentials: map[string]any{
- "pool_mode": true,
- },
- },
- expected: defaultPoolModeRetryCount,
- },
- {
- name: "supports_float64_from_json_credentials",
- account: &Account{
- Type: AccountTypeAPIKey,
- Platform: PlatformOpenAI,
- Credentials: map[string]any{
- "pool_mode": true,
- "pool_mode_retry_count": float64(5),
- },
- },
- expected: 5,
- },
- {
- name: "supports_json_number",
- account: &Account{
- Type: AccountTypeAPIKey,
- Platform: PlatformOpenAI,
- Credentials: map[string]any{
- "pool_mode": true,
- "pool_mode_retry_count": json.Number("4"),
- },
- },
- expected: 4,
- },
- {
- name: "supports_string_value",
- account: &Account{
- Type: AccountTypeAPIKey,
- Platform: PlatformOpenAI,
- Credentials: map[string]any{
- "pool_mode": true,
- "pool_mode_retry_count": "2",
- },
- },
- expected: 2,
- },
- {
- name: "negative_value_is_clamped_to_zero",
- account: &Account{
- Type: AccountTypeAPIKey,
- Platform: PlatformOpenAI,
- Credentials: map[string]any{
- "pool_mode": true,
- "pool_mode_retry_count": -1,
- },
- },
- expected: 0,
- },
- {
- name: "oversized_value_is_clamped_to_max",
- account: &Account{
- Type: AccountTypeAPIKey,
- Platform: PlatformOpenAI,
- Credentials: map[string]any{
- "pool_mode": true,
- "pool_mode_retry_count": 99,
- },
- },
- expected: maxPoolModeRetryCount,
- },
- {
- name: "invalid_value_falls_back_to_default",
- account: &Account{
- Type: AccountTypeAPIKey,
- Platform: PlatformOpenAI,
- Credentials: map[string]any{
- "pool_mode": true,
- "pool_mode_retry_count": "oops",
- },
- },
- expected: defaultPoolModeRetryCount,
- },
- }
- for _, tt := range tests {
- t.Run(tt.name, func(t *testing.T) {
- require.Equal(t, tt.expected, tt.account.GetPoolModeRetryCount())
- })
- }
- }
|